cloudairambo / core /database.py
rihancloud's picture
Deploy clean FastAPI backend without node_modules
99fdb5f
Raw History Blame Contribute Delete
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()