Spaces:
Paused
Paused
Download database.py from triflix/usermanagement: direct link, hf CLI and curl.
- Browser
- Download file 667 Bytes
-
https://huggingface.co/spaces/triflix/usermanagement/resolve/main/database.py
- Command line
-
hf download hf://spaces/triflix/usermanagement/database.py
-
curl -L -o database.py https://huggingface.co/spaces/triflix/usermanagement/resolve/main/database.py
667 Bytes
| import os | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| # Ensure SQLite DB is created in a writable path for Hugging Face Spaces and local | |
| DB_FILENAME = "app.db" | |
| DB_PATH = os.path.join(os.getcwd(), DB_FILENAME) | |
| SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_PATH}" | |
| # Create the database file if it doesn't exist (touch) | |
| if not os.path.exists(DB_PATH): | |
| open(DB_PATH, "a").close() | |
| engine = create_engine( | |
| SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |