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)