26 lines
592 B
Python
26 lines
592 B
Python
"""FastAPI Depends 工厂:把池化会话按请求注入,用后即还。"""
|
||||
|
|
from .database import milvus, mysql, neo4j, redis
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def get_db():
|
|||
|
|
"""仓储/服务层用 AsyncSession(UoW):注入 BaseRepository。"""
|
|||
|
|
async with mysql.get_session_factory()() as session:
|
|||
|
|
yield session
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def get_mysql_conn():
|
|||
|
|
async with mysql.get_session_factory()() as conn:
|
|||
|
|
yield conn
|
|||
|
|
|
|||
|
|
|
|||
|
|
def get_redis():
|
|||
|
|
yield redis.client()
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def get_neo4j_session():
|
|||
|
|
async with neo4j.get_session() as s:
|
|||
|
|
yield s
|
|||
|
|
|
|||
|
|
|
|||
|
|
def get_milvus():
|
|||
|
|
yield milvus.client()
|