-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.py
More file actions
54 lines (35 loc) · 916 Bytes
/
Copy pathscripts.py
File metadata and controls
54 lines (35 loc) · 916 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from types import coroutine
import click
import asyncpg
import toml
import asyncio
with open('config.toml', 'r') as f:
parsed_toml = toml.loads(f.read())
async def connect():
return await asyncpg.connect(parsed_toml["DB_CONN"])
async def initialize():
conn = await connect()
with open('sql/schema.sql', 'r') as f:
await conn.execute(f.read())
async def clear():
conn = await connect()
with open('sql/drop.sql', 'r') as f:
await conn.execute(f.read())
async def writeseed():
conn = await connect()
with open('sql/seed.sql', 'r') as f:
await conn.execute(f.read())
@click.group()
def cli():
pass
@cli.command()
def reset():
asyncio.run(clear())
asyncio.run(initialize())
click.echo('Initialized the database')
@cli.command()
def seed():
asyncio.run(writeseed())
click.echo('seed ')
if __name__ == '__main__':
cli()