You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
454 B
11 lines
454 B
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
|
|
from .config import DATABASE_URL
|
|
|
|
engine = create_async_engine(DATABASE_URL, echo=False, pool_pre_ping=True)
|
|
SessionLocal = async_sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)
|
|
|
|
async def get_db() -> AsyncSession:
|
|
"""获取一个异步数据库会话,用于依赖注入。"""
|
|
async with SessionLocal() as session:
|
|
yield session
|