Buckets:

download
raw
1 kB
"""Zen-Teams Database Connection"""
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool
from app.config import settings
from app.models import Base
engine = create_async_engine(
settings.DATABASE_URL,
echo=settings.DEBUG,
poolclass=NullPool if settings.DEBUG else None,
future=True,
)
async_session_maker = async_sessionmaker(
engine,
class_=AsyncSession,
expire_on_commit=False,
autoflush=False,
)
async def get_db():
"""Dependency for FastAPI to get DB session"""
async with async_session_maker() as session:
try:
yield session
finally:
await session.close()
async def init_db():
"""Initialize database tables"""
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
async def close_db():
"""Close database connections"""
await engine.dispose()

Xet Storage Details

Size:
1 kB
·
Xet hash:
4541abf9a4addda5289c32cbdae2fd0282c692af7332d2c22a5c0008bd6ac3e6

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.