Files

18 lines
512 B
Python
Executable File

from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from app.core.config import settings
# Create the Async Engine
engine = create_async_engine(settings.DATABASE_URL, echo=False, future=True)
# Create the Session Factory
AsyncSessionLocal = async_sessionmaker(
engine,
class_=AsyncSession,
expire_on_commit=False,
autoflush=False
)
# Dependency for FastAPI Routers
async def get_db():
async with AsyncSessionLocal() as session:
yield session