Skip to main content

Module query

Module query 

Source
Expand description

db query — execute arbitrary single-statement read-only SQL against the CLI’s local postgres pool. Returns the row set as typed JSON cells (Postgres → JSON via a per-cell decoder), with column metadata and the wire-protocol command tag.

Constraints:

  • Read-only: wrapped in SET LOCAL TRANSACTION READ ONLY server-side. Write attempts come back as Error::QueryReadOnlyViolation.
  • Timeout: required, humantime-parsed (30s, 5m, 1h30m). 0 is rejected at TryFrom<Args> time. The CLI threads it into both SET LOCAL statement_timeout (server) and tokio::time::timeout (client) so cancellation cleanly drops the connection without leaving the pool poisoned.
  • Token budget: optional --max-tokens N. When set, the CLI tokenizes the response per-part (command_tag, columns, each row) via tiktoken-rs o200k_base and sums. Over-budget responses error with Error::TokenBudgetExceeded { limit, actual } carrying the exact count and a refinement suggestion. 0 is rejected at TryFrom<Args> time (it means “no limit,” not “no tokens”).

Multi-statement queries, COPY … TO STDOUT|STDIN, and transaction-control verbs (BEGIN / COMMIT / ROLLBACK) are rejected up front by a cheap leading-token scan on the CLI side before the query reaches the database.

Modules§

request_schema
response_schema

Structs§

Args
Column
One result column. r#type is the Postgres pg_type.typname (e.g. "int8", "text", "jsonb", "timestamptz"). Callers needing precision/scale/array-element-type can inspect the name; richer typeinfo is deferred.
Command
Request
Response
Unary response from db query.

Enums§

Path
Schema

Functions§

execute
execute_jq