How to use the aiopg.connect function in aiopg

To help you get started, we’ve selected a few aiopg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DataDog / dd-trace-py / tests / contrib / aiopg / test_aiopg.py View on Github external
def _get_conn_and_tracer(self):
        conn = self._conn = yield from aiopg.connect(**POSTGRES_CONFIG)
        Pin.get_from(conn).clone(tracer=self.tracer).onto(conn)

        return conn, self.tracer
github adamcharnock / lightbus / tests / transactional_transport / test_reliability_transport.py View on Github external
async def start_firing(number):

        async with aiopg.connect(loop=loop, **pg_kwargs) as connection:
            async with connection.cursor(cursor_factory=cursor_factory) as cursor:
                bus = await transactional_bus_factory()
                await bus.client.register_api_async(dummy_api)

                for x in range(0, 50):
                    async with lightbus_set_database(bus, connection, apis=["my.dummy"]):
                        await bus.my.dummy.my_event.fire_async(field="a")
                        await cursor.execute(
                            "INSERT INTO test_table VALUES (%s)", [f"{number}-{x}"]
                        )

                await bus.client.close_async()
github aio-libs / aiopg / tests / test_connection.py View on Github external
async def test_connect_to_unsupported_port(unused_port, loop, pg_params):
    port = unused_port()
    pg_params['port'] = port

    with pytest.raises(psycopg2.OperationalError):
        await aiopg.connect(loop=loop, **pg_params)
github aio-libs / aiopg / tests / test_connection.py View on Github external
async def test___del__(loop, pg_params, warning):
    exc_handler = mock.Mock()
    loop.set_exception_handler(exc_handler)
    conn = await aiopg.connect(loop=loop, **pg_params)
    with warning(ResourceWarning):
        del conn
        gc.collect()

    msg = {'connection': mock.ANY,  # conn was deleted
           'message': 'Unclosed connection'}
    if loop.get_debug():
        msg['source_traceback'] = mock.ANY
        exc_handler.assert_called_with(loop, msg)
github DataDog / dd-trace-py / tests / contrib / aiopg / test_aiopg.py View on Github external
eq_(len(spans), 1)

        # Test unpatch
        unpatch()

        conn = yield from aiopg.connect(**POSTGRES_CONFIG)
        yield from (yield from conn.cursor()).execute('select \'blah\'')
        conn.close()

        spans = writer.pop()
        assert not spans, spans

        # Test patch again
        patch()

        conn = yield from aiopg.connect(**POSTGRES_CONFIG)
        Pin.get_from(conn).clone(service=service, tracer=tracer).onto(conn)
        yield from (yield from conn.cursor()).execute('select \'blah\'')
        conn.close()

        spans = writer.pop()
        assert spans, spans
        eq_(len(spans), 1)
github DataDog / dd-trace-py / tests / contrib / aiopg / test_aiopg_35.py View on Github external
def _get_conn_and_tracer(self):
        conn = self._conn = yield from aiopg.connect(**POSTGRES_CONFIG)
        Pin.get_from(conn).clone(tracer=self.tracer).onto(conn)

        return conn, self.tracer
github aio-libs / aiopg / tests / pep492 / test_async_await.py View on Github external
async def test_connect_context_manager(loop, pg_params):
    async with aiopg.connect(loop=loop, **pg_params) as conn:
        cursor = await conn.cursor()
        await cursor.execute('SELECT 42')
        resp = await cursor.fetchone()
        assert resp == (42,)
        cursor.close()
    assert conn.closed
github MagicStack / asyncpg / benchmarks / parallel.py View on Github external
async def aiopg_connect(args):
    conn = await aiopg.connect(user=args.pguser, host=args.pghost,
                               port=args.pgport)
    return conn