Arxen-backend / app /db /database.py
RantoG's picture
Upload 43 files
665eeaf verified
Raw
History Blame Contribute Delete
615 Bytes
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, sessionmaker
DATABASE_URL = os.environ.get("DATABASE_URL", "sqlite:///./arxen.db")
# Fix Supabase / Heroku postgres:// -> postgresql:// for SQLAlchemy compatibility
if DATABASE_URL.startswith("postgres://"):
DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://", 1)
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()