loom.core.sql.abc¶
Abstraction layer of the SQL subsystem: port, options, envelopes and errors.
- exception loom.core.sql.abc.RoleNotAllowedError(role, *, connection)[source]¶
Bases:
ForbiddenRaised when the caller role is not in the connection allowlist.
Without a configured allowlist every caller-provided role is rejected (fail-closed policy).
- exception loom.core.sql.abc.RoleRequiredError(connection)[source]¶
Bases:
ForbiddenRaised when no effective role can be resolved for a query.
A query never runs with the full default roles of the connection user: without a caller role and without
default_roleexecution is refused.- Parameters:
connection (str) – Name of the connection lacking an effective role.
- Return type:
None
- exception loom.core.sql.abc.RolesNotBoundError(connection)[source]¶
Bases:
ForbiddenRaised when the verified identity yields no allowed role.
Covers every fail-closed outcome of identity binding — no verified claims, a missing, empty or wrongly typed roles claim, or an empty intersection with the connection allowlist. The message is deliberately uniform so the response never reveals which part of the token failed; the precise reason is logged server-side.
- Parameters:
connection (str) – Name of the connection that refused the request.
- Return type:
None
- class loom.core.sql.abc.SqlColumn(*, name, type)[source]¶
Bases:
LoomFrozenStructColumn descriptor of a SQL result set.
- exception loom.core.sql.abc.SqlExecutionError(message)[source]¶
Bases:
RuleViolationRaised when the backend rejects a SQL statement.
Carries a sanitized message (backend error code plus first line, without host, DSN or stack trace).
- Parameters:
message (str) – Sanitized backend rejection message.
- Return type:
None
- class loom.core.sql.abc.SqlExecutionOptions(*, roles=(), readonly=True, limit=None, offset=0, max_execution_time=30)[source]¶
Bases:
LoomFrozenStructBackend-agnostic execution options resolved by the service policy.
Each executor translates these values to its native per-query mechanism (for ClickHouse: per-query
settings). The policy applies them last, so connection-level settings can never override them.- Parameters:
- roles¶
Effective roles for this single query, already validated against the connection allowlist. Several roles apply the union of their privileges; empty means no role at all (internal probes only).
- class loom.core.sql.abc.SqlExecutor(*args, **kwargs)[source]¶
Bases:
ProtocolPort implemented by concrete SQL backends.
Exists for dependency inversion (the service never imports driver code) and for testing with fakes. Documented as a contract in evolution until a second backend implementation lands.
- async execute(sql, *, parameters=None, options)[source]¶
Execute sql with server-side bound parameters under options.
- Parameters:
sql (str) – SQL statement with native parameter placeholders.
parameters (Mapping[str, Any] | None) – Values bound server-side; never interpolated locally.
options (SqlExecutionOptions) – Policy-resolved execution options for this single query.
- Returns:
The standard tabular result envelope.
- Raises:
SqlExecutionError – When the backend rejects the statement.
- Return type:
- class loom.core.sql.abc.SqlQueryResult(*, columns, rows, row_count, limit, offset, has_more, elapsed_ms)[source]¶
Bases:
LoomFrozenStructStandard tabular envelope returned for any SQL statement.
- Parameters:
- columns¶
Ordered column descriptors of the result set.
- Type: