ts-lyceum-back/db/db.py
2023-11-30 21:01:57 +03:00

18 lines
No EOL
510 B
Python

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()