Spaces:
Runtime error
Runtime error
Download core/database.py from cloudaiRambo/cloudairambo: direct link, hf CLI and curl.
- Browser
- Download file 758 Bytes
-
https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/core/database.py
- Command line
-
hf download hf://spaces/cloudaiRambo/cloudairambo/core/database.py
-
curl -L -o database.py https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/core/database.py
758 Bytes
| # core/database.py | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| from sqlalchemy.pool import StaticPool | |
| # SQLAlchemy Base | |
| Base = declarative_base() | |
| # 🚀 100% in RAM using SQLite (Zero external DB, 100% Free) | |
| # StaticPool ensures all FastAPI threads share the same in-memory database | |
| engine = create_engine( | |
| "sqlite:///:memory:", | |
| connect_args={"check_same_thread": False}, | |
| poolclass=StaticPool, | |
| future=True, | |
| echo=False | |
| ) | |
| # Session factory | |
| SessionLocal = sessionmaker( | |
| bind=engine, | |
| autoflush=False, | |
| autocommit=False | |
| ) | |
| # Dependency for routes (kept identical so nothing breaks) | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |