-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathsql.py
31 lines (22 loc) · 959 Bytes
/
sql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import asyncio
import asyncpg
import logging
from config import host, PG_PASS, PG_USER
logging.basicConfig(format=u'%(filename)s [LINE:%(lineno)d] #%(levelname)-8s [%(asctime)s] %(message)s',
level=logging.INFO)
async def create_db():
create_db_command = open("create_db.sql", "r").read()
logging.info("Connecting to database...")
conn: asyncpg.Connection = await asyncpg.connect(user=PG_USER,
password=PG_PASS,
host=host)
await conn.execute(create_db_command)
await conn.close()
logging.info("Table users created")
async def create_pool():
return await asyncpg.create_pool(user=PG_USER,
password=PG_PASS,
host=host)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(create_db())