Spaces:
Sleeping
Sleeping
Download app/lib/database.py from harsh-dev/google-flan-t5-large: direct link, hf CLI and curl.
- Browser
- Download file 732 Bytes
-
https://huggingface.co/spaces/harsh-dev/google-flan-t5-large/resolve/main/app/lib/database.py
- Command line
-
hf download hf://spaces/harsh-dev/google-flan-t5-large/app/lib/database.py
-
curl -L -o database.py https://huggingface.co/spaces/harsh-dev/google-flan-t5-large/resolve/main/app/lib/database.py
732 Bytes
| from collections.abc import AsyncGenerator | |
| from sqlalchemy.ext.asyncio import ( | |
| AsyncSession, | |
| async_sessionmaker, | |
| create_async_engine, | |
| ) | |
| from sqlalchemy.orm import DeclarativeBase | |
| from app.lib.config import settings | |
| class Base(DeclarativeBase): | |
| pass | |
| engine = create_async_engine( | |
| settings.database_url, | |
| echo=settings.debug, | |
| pool_pre_ping=True, # critical for Neon cold-start / stale connections | |
| pool_recycle=300, # recycle before Neon's idle timeout | |
| ) | |
| AsyncSessionLocal = async_sessionmaker( | |
| engine, | |
| class_=AsyncSession, | |
| expire_on_commit=False, | |
| ) | |
| async def get_db() -> AsyncGenerator[AsyncSession, None]: | |
| async with AsyncSessionLocal() as session: | |
| yield session |