Anish-530
feat: Day 2 setup FastAPI core, SQLAlchemy models, and Alembic
cf8823b
Raw History Blame Contribute Delete
598 Bytes
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
from app.core.config import settings
engine = create_async_engine(
settings.DATABASE_URL,
echo=False,
pool_size=5,
max_overflow=10,
pool_timeout=30,
pool_recycle=1800,
)
AsyncSessionLocal = async_sessionmaker(
bind=engine,
class_=AsyncSession,
expire_on_commit=False,
autocommit=False,
autoflush=False,
)
async def get_db():
async with AsyncSessionLocal() as session:
try:
yield session
finally:
await session.close()