Files
gcontext/api/app/db.py
T
bernatsamperaandClaude Fable 5 aca7523754 Add workflows API, the marketplace backend (marketplace task 3b)
FastAPI + Postgres service that stores workflow templates as file
bundles with indexed manifest fields, submit-for-review publishing,
and moderation endpoints behind an admin token.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-08 13:15:47 +02:00

31 lines
665 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import Session, sessionmaker
from . import settings
from .models import Base
_engine = None
_session_factory = None
def engine():
global _engine
if _engine is None:
_engine = create_engine(settings.database_url(), pool_pre_ping=True)
return _engine
def init_db() -> None:
Base.metadata.create_all(engine())
def get_session():
global _session_factory
if _session_factory is None:
_session_factory = sessionmaker(bind=engine(), expire_on_commit=False)
session: Session = _session_factory()
try:
yield session
finally:
session.close()