INNER CODE UNIT · Python
lifespan
Evil0ctal/Fast-Powerful-Whisper-AI-Services-API · app/main.py:74
async def lifespan(application: FastAPI):
"""
FastAPI 生命周期上下文管理器 | FastAPI Lifecycle context manager
:param application: FastAPI 应用实例 | FastAPI application instance
:return: None
"""
# 选择数据库管理器并初始化数据库 | Choose the database manager and initialize the database
if Settings.DatabaseSettings.db_type == "sqlite":
database_url = Settings.DatabaseSettings.sqlite_url
elif Settings.DatabaseSettings.db_type == "mysql":
database_url = Settings.DatabaseSettings.mysql_url
else:
raise RuntimeError("Can not recognize the database type, please check the database type in the settings.")
db_manager = DatabaseManager(
database_type=Settings.DatabaseSettings.db_type,
database_url=database_url
)