Spaces:
Runtime error
Runtime error
Download app/db.py from FireBird-Tech/autoform-backend: direct link, hf CLI and curl.
- Browser
- Download file 802 Bytes
-
https://huggingface.co/spaces/FireBird-Tech/autoform-backend/resolve/main/app/db.py
- Command line
-
hf download hf://spaces/FireBird-Tech/autoform-backend/app/db.py
-
curl -L -o db.py https://huggingface.co/spaces/FireBird-Tech/autoform-backend/resolve/main/app/db.py
802 Bytes
| import os | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, DeclarativeBase | |
| DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./app.db") | |
| class Base(DeclarativeBase): | |
| pass | |
| if DATABASE_URL.startswith("sqlite"): | |
| engine = create_engine( | |
| DATABASE_URL, | |
| connect_args={"check_same_thread": False}, | |
| ) | |
| else: | |
| engine = create_engine( | |
| DATABASE_URL, | |
| pool_pre_ping=True, # validate connections before use to avoid stale sockets | |
| pool_recycle=280, # recycle before Neon's ~5 min idle timeout | |
| pool_size=5, | |
| max_overflow=10, | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |