feat: implement full API - all admin/user routes, RBAC, sync service, collector, MySQL config, superadmin hanbin credentials
9d66536 Download app/database.py from binhugg2/api: direct link, hf CLI and curl.
- Browser
- Download file 748 Bytes
-
https://huggingface.co/spaces/binhugg2/api/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/binhugg2/api/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/binhugg2/api/resolve/main/app/database.py
748 Bytes
| from collections.abc import AsyncGenerator | |
| from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine | |
| from sqlalchemy.orm import DeclarativeBase | |
| from app.config import settings | |
| engine = create_async_engine(settings.DATABASE_URL, echo=False, connect_args={"check_same_thread": False} if "sqlite" in settings.DATABASE_URL else {}) | |
| async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) | |
| class Base(DeclarativeBase): | |
| pass | |
| async def get_db() -> AsyncGenerator[AsyncSession, None]: | |
| async with async_session() as session: | |
| try: | |
| yield session | |
| await session.commit() | |
| except Exception: | |
| await session.rollback() | |
| raise | |