|
from tortoise import Tortoise |
|
|
|
DATABASE_URL = "sqlite://db.sqlite3" |
|
|
|
TORTOISE_ORM = { |
|
"connections": {"default": DATABASE_URL}, |
|
"apps": { |
|
"models": { |
|
"models": [ |
|
'App.routers.stocks.models', |
|
'App.routers.tasks.models', |
|
'App.routers.utt.models', |
|
'App.routers.users.models', |
|
'App.routers.portfolio.models', |
|
'App.routers.bonds.models', |
|
"aerich.models" |
|
], |
|
"default_connection": "default", |
|
} |
|
} |
|
} |
|
|
|
async def init_db(): |
|
await Tortoise.init( |
|
db_url=DATABASE_URL, |
|
modules={'models': [ |
|
'App.routers.stocks.models', |
|
'App.routers.tasks.models', |
|
'App.routers.utt.models', |
|
'App.routers.users.models', |
|
'App.routers.portfolio.models', |
|
'App.routers.bonds.models' |
|
]} |
|
) |
|
await Tortoise.generate_schemas() |
|
|
|
async def close_db(): |
|
await Tortoise.close_connections() |
|
|
|
|
|
async def clear_db(): |
|
for model in Tortoise.apps.get('models').values(): |
|
await model.all().delete() |