Spaces:
Paused
Paused
Download app/database.py from truegleai/eye-dentify-api: direct link, hf CLI and curl.
- Browser
- Download file 986 Bytes
-
https://huggingface.co/spaces/truegleai/eye-dentify-api/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/truegleai/eye-dentify-api/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/truegleai/eye-dentify-api/resolve/main/app/database.py
986 Bytes
| from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker | |
| from sqlalchemy.orm import DeclarativeBase | |
| from app.config import get_settings | |
| settings = get_settings() | |
| # SQLite doesn't support connection pooling | |
| is_sqlite = "sqlite" in settings.DATABASE_URL.lower() | |
| if is_sqlite: | |
| engine = create_async_engine( | |
| settings.DATABASE_URL, | |
| echo=settings.DEBUG, | |
| ) | |
| else: | |
| engine = create_async_engine( | |
| settings.DATABASE_URL, | |
| echo=settings.DEBUG, | |
| pool_pre_ping=True, | |
| pool_size=10, | |
| max_overflow=20, | |
| ) | |
| async_session_factory = async_sessionmaker( | |
| engine, | |
| class_=AsyncSession, | |
| expire_on_commit=False, | |
| ) | |
| class Base(DeclarativeBase): | |
| pass | |
| async def get_db() -> AsyncSession: | |
| async with async_session_factory() as session: | |
| try: | |
| yield session | |
| await session.commit() | |
| except Exception: | |
| await session.rollback() | |
| raise | |