import asyncpg import asyncio from os.path import isfile from sys import exit from risotto.config import get_config async def main(): sql_filename = get_config()['global']['sql_filename'] if not isfile(sql_filename): print('no sql file to import') exit() db_conf = get_config()['database']['dsn'] pool = await asyncpg.create_pool(db_conf) async with pool.acquire() as connection: async with connection.transaction(): with open(sql_filename, 'r') as sql: await connection.execute(sql.read()) if __name__ == '__main__': loop = asyncio.get_event_loop() loop.run_until_complete(main())