verbose live UI + tool-level SSE events + Groq default + regression tests

This commit is contained in:
2026-06-03 05:04:29 -03:00
parent 131f4d9b86
commit e124a8a7d9
69 changed files with 3030 additions and 137 deletions

39
api/tools/db.py Normal file
View File

@@ -0,0 +1,39 @@
"""SQLAlchemy engine for the warehouse.
Per-connection defaults (search_path, statement_timeout) are baked into the
engine via libpq's `options` connect_arg so we never SET them at the SQL
layer. Read-only mode for query execution is requested via SQLAlchemy's
`execution_options(postgresql_readonly=True)`.
"""
from __future__ import annotations
from functools import lru_cache
from sqlalchemy import create_engine
from sqlalchemy.engine import Engine
from api.config import get_settings
SCHEMA = "financial"
DEFAULT_STATEMENT_TIMEOUT_MS = 10_000
@lru_cache(maxsize=1)
def get_engine() -> Engine:
url = get_settings().database_url
if url.startswith("postgresql://"):
url = url.replace("postgresql://", "postgresql+psycopg://", 1)
return create_engine(
url,
pool_pre_ping=True,
future=True,
# libpq -c options run before any SQL the app issues — no need to
# SET search_path / statement_timeout at execution time.
connect_args={
"options": (
f"-c search_path={SCHEMA},public "
f"-c statement_timeout={DEFAULT_STATEMENT_TIMEOUT_MS}"
),
},
)