Files
GTI_GERENCIADOR_FISCAL/central/app/db.py
T

16 lines
508 B
Python

"""SQLAlchemy session setup for central PostgreSQL only."""
from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker
from .config import settings
engine = create_engine(settings.database_url, pool_pre_ping=True)
SessionLocal = sessionmaker(bind=engine, expire_on_commit=False)
def database_is_available() -> bool:
try:
with engine.connect() as connection:
connection.execute(text("SELECT 1"))
return True
except Exception:
return False