Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /InferiaAI_InferiaLLM /src /api_gateway /db /database.py
| """ | |
| Database configuration and session management. | |
| Using SQLAlchemy with asyncpg. | |
| """ | |
| from api_gateway.config import settings | |
| from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker | |
| from sqlalchemy.ext.declarative import declarative_base | |
| # Provided Connection String | |
| # Note: Ensure we use the sqlalchemy-compatible URL from settings | |
| DATABASE_URL = settings.database_url | |
| if DATABASE_URL.startswith("postgresql://"): | |
| DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://", 1) | |
| engine = create_async_engine( | |
| DATABASE_URL, | |
| echo=False, # Set to True for SQL logging | |
| future=True, | |
| pool_pre_ping=True, | |
| pool_recycle=1800, | |
| # Production Tuning: Increase pool size to handle higher concurrency | |
| pool_size=20, | |
| max_overflow=40, | |
| ) | |
| AsyncSessionLocal = async_sessionmaker( | |
| engine, | |
| expire_on_commit=False, | |
| autoflush=False, | |
| ) | |
| Base = declarative_base() | |
| async def get_db(): | |
| """Dependency for getting async DB session.""" | |
| async with AsyncSessionLocal() as session: | |
| try: | |
| yield session | |
| finally: | |
| await session.close() | |
Xet Storage Details
- Size:
- 1.14 kB
- Xet hash:
- 76c0b5c52c8feb53fb30637de71b05b7f01fd27e26a2bd0617aeaa947ba58d5d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.