How to use the aiopg.sa.create_engine 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 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 foglamp / FogLAMP / src / python / foglamp / translators / statistics_to_pi.py View on Github external
Raises:
        Exception: cannot complete loading data in memory

    Todo:
        it should evolve using the DB layer

    """

    global _num_sent
    global _num_unsent

    new_position = 0
    data_available = False

    try:
        async with aiopg.sa.create_engine(_CONNECTION_STRING) as engine:
            async with engine.acquire() as conn:

                    _logger.debug("{0}".format("omf_translator_perf - DB read START "))

                    # Reads rows from the Storage layer and sends them to the PICROMF
                    async for db_row in conn.execute(_statistics_history_tbl.select()
                                                     .where(_statistics_history_tbl.c.id > position)
                                                     .order_by(_statistics_history_tbl.c.id).limit(_block_size)):

                        message = "### sensor information ##################################################"
                        _logger.debug("{0}".format(message))

                        # Identification of the object/sensor
                        sensor_id = db_row.key
                        sensor_id = sensor_id.strip().lower()
                        measurement_id = "measurement_" + sensor_id
github steemit / hivemind / hive / server / db.py View on Github external
async def init(self, url):
        """Initialize the aiopg.sa engine."""
        conf = make_url(url)
        self.db = await create_engine(user=conf.username,
                                      database=conf.database,
                                      password=conf.password,
                                      host=conf.host,
                                      port=conf.port,
                                      maxsize=20,
                                      **conf.query)
github aio-libs / aiopg / examples / simple_sa_transaction.py View on Github external
async def go():
    engine = await create_engine(user='aiopg',
                                 database='aiopg',
                                 host='127.0.0.1',
                                 password='passwd')
    async with engine:
        async with engine.acquire() as conn:
            await create_sa_transaction_tables(conn)

            await success_transaction(conn)
            await fail_transaction(conn)

            await success_nested_transaction(conn)
            await fail_nested_transaction(conn)
            await fail_first_nested_transaction(conn)
github aio-libs / aiopg / examples / sa_oldstyle.py View on Github external
async def go():
    engine = await create_engine(user='aiopg',
                                      database='aiopg',
                                      host='127.0.0.1',
                                      password='passwd')

    await create_tables(engine)
    await fill_data(engine)
    await count(engine)
    await show_julia(engine)
    await ave_age(engine)
github aio-libs / aiohttp-demos / demos / polls / aiohttpdemo_polls / db.py View on Github external
async def init_pg(app):
    conf = app['config']['postgres']
    engine = await aiopg.sa.create_engine(
        database=conf['database'],
        user=conf['user'],
        password=conf['password'],
        host=conf['host'],
        port=conf['port'],
        minsize=conf['minsize'],
        maxsize=conf['maxsize'],
    )
    app['db'] = engine
github steemit / sbds / sbds / storages / db / utils.py View on Github external
async def async_create_aiopg_engine(database_url, minsize=10, maxsize=30, **kwargs):
    sa_db_url = make_url(database_url)
    return await aiopg.sa.create_engine(
        user=sa_db_url.username,
        password=sa_db_url.password,
        host=sa_db_url.host,
        port=sa_db_url.port,
        dbname=sa_db_url.database,
        minsize=minsize,
        maxsize=maxsize,
        **kwargs)
github 2gis / vmmaster / core / database.py View on Github external
async def create_connection(self):
        return await create_engine(
            dsn=self.app.cfg.DATABASE,
            loop=self.app.loop
        )