Example #1
0
async def insertdb(database_uri, titles):
    async with asyncpgsa.create_pool(dsn=database_uri) as conn:
        for tit in titles:
            slug = slugify(tit)
            query = f"insert into game(title, slug, platform_id) values ('{tit}', '{slug}', '1');"
            # print(tit, '+++', slug)
            await conn.execute(query)
Example #2
0
def pool(event_loop):
    _pool = event_loop.run_until_complete(asyncpgsa.create_pool(host=HOST,
                                                                port=PORT,
                                                                database='postgres',
                                                                user=USER,
                                                                password=PASS,
                                                                min_size=1,
                                                                max_size=10))
    yield _pool
Example #3
0
def pool(event_loop):
    _pool = event_loop.run_until_complete(
        asyncpgsa.create_pool(host=HOST,
                              port=PORT,
                              database='postgres',
                              user=USER,
                              password=PASS,
                              min_size=1,
                              max_size=10))
    yield _pool
Example #4
0
async def main():
    titles = await parse_csv(csv_file)
    async with asyncpgsa.create_pool(dsn=database_uri) as conn:
        for tit in titles:
            print(tit)
            img = (static + '/' + tit + '.jpg')
            slug = slugify(tit)
            query = """insert into game_xbox360(title, slug, image, platform_id) values ($1, $2, $3, '1');"""
            print(query)
            await conn.execute(query, tit, slug, img)
Example #5
0
 async def init_db(config):
     async with pg.create_pool(
             host=str(config.db_addr[0]),
             port=config.db_addr[1],
             user=config.db_user,
             password=config.db_password,
             database=config.db_name,
             min_size=1,
             max_size=3,
     ) as pool:
         if config.drop_tables:
             await drop_tables(config, pool)
         if config.create_tables:
             await create_tables(config, pool)
         if config.populate_fixtures:
             await populate_fixtures(config, pool)
Example #6
0
def pool(event_loop):
    from asyncpgsa import create_pool
    from . import HOST, PORT, USER, PASS, DB_NAME

    pool = create_pool(min_size=1,
                       max_size=3,
                       host=HOST,
                       port=PORT,
                       user=USER,
                       password=PASS,
                       database=DB_NAME,
                       timeout=1,
                       loop=event_loop)

    event_loop.run_until_complete(pool)

    try:
        yield pool
    finally:
        event_loop.run_until_complete(pool.close())
Example #7
0
def pool(event_loop):
    from asyncpgsa import create_pool
    from . import HOST, PORT, USER, PASS, DB_NAME

    pool = create_pool(
        min_size=1,
        max_size=3,
        host=HOST,
        port=PORT,
        user=USER,
        password=PASS,
        database=DB_NAME,
        timeout=1,
        loop=event_loop
    )

    event_loop.run_until_complete(pool)

    try:
        yield pool
    finally:
        event_loop.run_until_complete(pool.close())
Example #8
0
async def cleanup_ctx_databases(app, cfg_key='default', app_key='db'):
    import asyncpgsa
    from dvhb_hybrid.amodels import AppModels

    app.models = app.m = AppModels(app)

    async def init(connection):
        for t in ['json', 'jsonb']:
            await connection.set_type_codec(
                t,
                encoder=lambda x: x,
                decoder=json.loads,
                schema='pg_catalog',
            )

    dbparams = app.context.config.databases.get(cfg_key)
    if 'uri' in dbparams:
        dbargs, dbkwargs = (dbparams.uri, ), {}
    else:
        dbargs, dbkwargs = (), dbparams

    async with asyncpgsa.create_pool(*dbargs, init=init, **dbkwargs) as pool:
        app[app_key] = pool
        yield