refactor(core): route integrations through adapter factory

This commit is contained in:
2026-07-11 20:52:41 +02:00
parent 1e0911bb6a
commit dbbab6d005
8 changed files with 245 additions and 105 deletions
+6 -34
View File
@@ -90,46 +90,18 @@ def validate_or_exit(cfg, sql: str, session_id: str | None):
return result
def _ro_engine(cfg):
"""Engine sul target con search_path impostato allo schema (nomi non qualificati)."""
from sqlalchemy import create_engine
db = cfg.database
url = f"postgresql+psycopg2://{db.user}:{db.password}@{db.host}:{db.port}/{db.database}"
return create_engine(
url, echo=False,
connect_args={"options": f"-csearch_path={db.db_schema}"},
)
def _rest_client(cfg):
from tht.rest.client import RestClient
return RestClient(cfg.rest)
def do_explain(cfg, sql: str):
"""EXPLAIN secondo il transport configurato (direct|rest)."""
if cfg.database.transport == "rest":
from tht.rest.execute import explain_rest
"""EXPLAIN through the configured DWH adapter."""
from tht.adapters.factory import build_dwh
return explain_rest(_rest_client(cfg), sql)
from tht.execute import explain
return explain(_ro_engine(cfg), sql, timeout_ms=cfg.execution.statement_timeout_ms)
return build_dwh(cfg).explain(sql)
def _run_transport(cfg, sql: str, *, limit: int):
"""Dispatch all'esecutore controllato secondo il transport (direct|rest)."""
if cfg.database.transport == "rest":
from tht.rest.execute import run_controlled_rest
"""Dispatch through the configured DWH adapter."""
from tht.adapters.factory import build_dwh
return run_controlled_rest(_rest_client(cfg), sql, limit=limit)
from tht.execute import run_controlled
return run_controlled(
_ro_engine(cfg), sql, limit=limit, timeout_ms=cfg.execution.statement_timeout_ms
)
return build_dwh(cfg).run_query(sql, limit=limit)
def do_run(cfg, sql: str, *, limit: int, offset: int = 0):