Spaces:
Runtime error
Runtime error
File size: 758 Bytes
99fdb5f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # 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()
|