Spaces:
Runtime error
Runtime error
| 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() | |