Spaces:
Sleeping
Sleeping
Download app/database.py from pramodmisra/GMtracker: direct link, hf CLI and curl.
- Browser
- Download file 571 Bytes
-
https://huggingface.co/spaces/pramodmisra/GMtracker/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/pramodmisra/GMtracker/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/pramodmisra/GMtracker/resolve/main/app/database.py
571 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| # Use SQLite for simplicity in Hugging Face Spaces | |
| DATABASE_URL = "sqlite:///./gmtracker.db" | |
| engine = create_engine( | |
| DATABASE_URL, connect_args={"check_same_thread": False} | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def init_db(): | |
| Base.metadata.create_all(bind=engine) |