refactor(app): update database code

This commit is contained in:
MingxuanGame
2025-08-18 16:37:30 +00:00
parent 6bae937e01
commit 1c65b21bb9
34 changed files with 167 additions and 188 deletions

View File

@@ -3,9 +3,11 @@ from __future__ import annotations
from collections.abc import AsyncIterator, Callable
from contextvars import ContextVar
import json
from typing import Annotated
from app.config import settings
from fastapi import Depends
from pydantic import BaseModel
import redis.asyncio as redis
from sqlalchemy.ext.asyncio import create_async_engine
@@ -52,7 +54,12 @@ async def get_db():
yield session
def with_db():
return AsyncSession(engine)
DBFactory = Callable[[], AsyncIterator[AsyncSession]]
Database = Annotated[AsyncSession, Depends(get_db)]
async def get_db_factory() -> DBFactory: