Created
November 27, 2019 23:57
-
-
Save alairock/8ad692c2bcd8952603067c6bd44b073c to your computer and use it in GitHub Desktop.
Example database file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncpg | |
import asyncio | |
DATABASE_POOL = None | |
async def get_connection_pool(): | |
if DATABASE_POOL is None: | |
await asyncio.sleep(1) | |
return await get_connection_pool() | |
return DATABASE_POOL | |
async def connect(): | |
global DATABASE_POOL | |
DATABASE_POOL = await asyncpg.create_pool( | |
user='guest', | |
password='guest', | |
database='ninja', | |
host='127.0.0.1') | |
print('DB Connection pool created') | |
return DATABASE_POOL | |
if __name__ == '__main__': | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(connect()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment