27 lines
565 B
Python
27 lines
565 B
Python
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
from app.core.config import settings
|
|
|
|
engine = create_async_engine(
|
|
settings.DATABASE_URL,
|
|
echo=True, # Set to False in production
|
|
future=True
|
|
)
|
|
|
|
SessionLocal = async_sessionmaker(
|
|
autocommit=False,
|
|
autoflush=False,
|
|
bind=engine,
|
|
class_=AsyncSession,
|
|
expire_on_commit=False
|
|
)
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
async def get_db():
|
|
async with SessionLocal() as session:
|
|
yield session
|