Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 682 Bytes
1b7f275 b0dfd19 1b7f275 b0dfd19 f73d61a b0dfd19 1b7f275 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from app.core.config import settings
engine_kwargs = {
"echo": False,
"pool_pre_ping": True,
"pool_recycle": 3600,
}
if not settings.DATABASE_URL.startswith("sqlite"):
engine_kwargs.update(
{
"pool_size": 10,
"max_overflow": 20,
"pool_timeout": 30,
}
)
engine = create_async_engine(settings.DATABASE_URL, **engine_kwargs)
SessionLocal = async_sessionmaker(
autocommit=False, autoflush=False, bind=engine, class_=AsyncSession
)
async def get_db():
async with SessionLocal() as session:
yield session
|