Initial commit
This commit is contained in:
commit
8b18f2439c
13 changed files with 960 additions and 0 deletions
18
db/db.py
Normal file
18
db/db.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from tortoise import Tortoise
|
||||
|
||||
|
||||
def init(app, generate_schemas: bool = False) -> None:
|
||||
|
||||
@app.on_event("startup")
|
||||
async def __init():
|
||||
# TODO: Поддержка других БД
|
||||
await Tortoise.init(
|
||||
db_url='sqlite://data.sqlite3',
|
||||
modules={'models': ['db.models.user']}
|
||||
)
|
||||
if generate_schemas:
|
||||
await Tortoise.generate_schemas(safe=True)
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def __close():
|
||||
await Tortoise.close_connections()
|
Loading…
Add table
Add a link
Reference in a new issue