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 ONLYserver-side. Write attempts come back asError::QueryReadOnlyViolation. - Timeout: required, humantime-parsed (
30s,5m,1h30m).0is rejected atTryFrom<Args>time. The CLI threads it into bothSET LOCAL statement_timeout(server) andtokio::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) viatiktoken-rso200k_base and sums. Over-budget responses error withError::TokenBudgetExceeded { limit, actual }carrying the exact count and a refinement suggestion.0is rejected atTryFrom<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§
Structs§
- Args
- Column
- One result column.
r#typeis the Postgrespg_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.