from fastapi import FastAPI
from tortoise.contrib.fastapi import register_tortoise

def create_app() -> FastAPI:
    app = FastAPI()

    register_rotuer(app)
    register_db(app)
    return app


def register_rotuer(app: FastAPI) -> None:
    """注册路由"""
    from app.api import routers
    app.include_router(routers)


def register_db(app: FastAPI) -> None:
    """"初始化数据库并根据数据模型生成对应的表"""
    register_tortoise(
            app,
            db_url="mysql://choozmo:pAssw0rd@db.ptt.cx:3306/test",
            modules={"models": ["app.models.models"]},# 这是一个列表用来指明我们的模型文件的路径
            generate_schemas=True,
            add_exception_handlers=True)