How to use aiopg - 10 common examples

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 aio-libs / aiopg / tests / test_transaction.py View on Github external
async def test_transaction_readonly_oldstyle(engine):
    with (await engine) as cur:
        tr = Transaction(cur, IsolationLevel.serializable, readonly=True)

        await tr.begin()
        resp = await cur.execute('select * from tbl where id = 22')
        row = await resp.fetchone()

        assert row.id == 22
        assert row.name == 'read only'
        await tr.commit()
github aio-libs / aiopg / tests / test_transaction.py View on Github external
async def two_commit(cur):
    tr = Transaction(cur, IsolationLevel.read_committed)
    await tr.begin()
    await tr.commit()
    await tr.commit()
github foglamp / FogLAMP / tests / integration / foglamp / common / test_configuration_manager.py View on Github external
async def delete_from_configuration():
    """ Remove initial data from configuration table """
    sql = sa.text("DELETE FROM foglamp.configuration WHERE key IN {}".format(_KEYS))
    async with aiopg.sa.create_engine(_CONNECTION_STRING) as engine:
        async with engine.acquire() as conn:
            await conn.execute(sql)
github vmagamedov / hiku / docs / test_asyncio.py View on Github external
async def init_db(pg_dsn, *, loop):
    db_name = 'test_{}'.format(uuid.uuid4().hex)
    async with aiopg.sa.create_engine(pg_dsn, loop=loop) as db_engine:
        async with db_engine.acquire() as conn:
            await conn.execute('CREATE DATABASE {0}'.format(db_name))
            return db_name
github aio-libs / aiopg / tests / test_sa.py View on Github external
def create_pool(self, **kwargs):
        pool = yield from sa.create_pool(database='aiopg',
                                         user='aiopg',
                                         password='passwd',
                                         host='127.0.0.1',
                                         loop=self.loop,
                                         **kwargs)
        with (yield from pool.cursor()) as cur:
            yield from cur.execute("DROP TABLE IF EXISTS tbl")
            yield from cur.execute("CREATE TABLE tbl "
                                   "(id serial, name varchar(255))")
        return pool
github aio-libs / aiohttp_admin / tests / db_fixtures.py View on Github external
async def init_postgres(conf, loop):
        engine = await aiopg.sa.create_engine(
            database=conf['database'],
            user=conf['user'],
            password=conf['password'],
            host=conf['host'],
            port=conf['port'],
            minsize=1,
            maxsize=2,
            loop=loop)
        return engine
    engine = loop.run_until_complete(init_postgres(pg_params, loop))
github foglamp / FogLAMP / tests / integration / foglamp / services / core / test_scheduler.py View on Github external
async def _get_connection_pool(self) -> aiopg.sa.Engine:
        """Returns a database connection pool object"""
        if self._engine is None:
            self._engine = await aiopg.sa.create_engine(_CONNECTION_STRING)
        return self._engine
github foglamp / FogLAMP / tests / unit-tests / python / foglamp_test / services / core / test_scheduler.py View on Github external
async def _get_connection_pool(self) -> aiopg.sa.Engine:
        """Returns a database connection pool object"""
        if self._engine is None:
            self._engine = await aiopg.sa.create_engine(_CONNECTION_STRING)
        return self._engine
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()