You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
693 B
Python
23 lines
693 B
Python
from __future__ import annotations
|
|
from aiohttp import web
|
|
from utils.server import register_server_module
|
|
|
|
from server.model.base import BaseModel
|
|
from service.database import DatabaseService
|
|
|
|
async def init_database(app: web.Application):
|
|
dbs = await DatabaseService.create(app)
|
|
print("Database connected.")
|
|
|
|
async with dbs.engine.begin() as conn:
|
|
await conn.run_sync(BaseModel.metadata.create_all)
|
|
|
|
async def close_database(app: web.Application):
|
|
dbs = await DatabaseService.create(app)
|
|
await dbs.close()
|
|
|
|
def init(app: web.Application):
|
|
app.on_startup.append(init_database)
|
|
app.on_cleanup.append(close_database)
|
|
|
|
register_server_module("database", init) |