Первоначальная версия VidConf
This commit is contained in:
24
backend/core/db.py
Normal file
24
backend/core/db.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Настройка асинхронного движка SQLAlchemy и сеанса."""
|
||||
|
||||
from collections.abc import AsyncGenerator
|
||||
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
AsyncEngine,
|
||||
AsyncSession,
|
||||
async_sessionmaker,
|
||||
create_async_engine,
|
||||
)
|
||||
|
||||
from core.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
engine: AsyncEngine = create_async_engine(settings.database_url, pool_pre_ping=True)
|
||||
|
||||
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)
|
||||
|
||||
|
||||
async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
"""Зависимость FastAPI, возвращающая `AsyncSession`."""
|
||||
async with async_session_maker() as session:
|
||||
yield session
|
||||
Reference in New Issue
Block a user