Spaces:
Sleeping
Sleeping
Download app/database.py from phx8nix/lexflow-backend: direct link, hf CLI and curl.
- Browser
- Download file 656 Bytes
-
https://huggingface.co/spaces/phx8nix/lexflow-backend/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/phx8nix/lexflow-backend/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/phx8nix/lexflow-backend/resolve/main/app/database.py
656 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| import os | |
| # Use SQLite if PostgreSQL is not available (no Docker needed) | |
| DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./lexflow.db") | |
| # SQLite needs connect_args for check_same_thread | |
| connect_args = {} | |
| if DATABASE_URL.startswith("sqlite"): | |
| connect_args = {"check_same_thread": False} | |
| engine = create_engine(DATABASE_URL, connect_args=connect_args) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |