Skip to content

Add native SQL formatting with rtree format - #82

Merged
rmorehig merged 3 commits into
mainfrom
rafa/query-format
Oct 16, 2026
Merged

rmorehig merged 3 commits into
mainfrom
rafa/query-format

Conversation

@rmorehig

@rmorehig rmorehig commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Add rtree format to format complete SQL through POST /v1/query-format without executing SQL. Both rtree query and rtree format accept positional SQL, --sql, --query, and -q. Omitted SQL or - reads stdin, including shell file redirection and cat pipes. Supplying multiple SQL arguments is rejected.

rtree format "select 1"
rtree format -q "select 1"
rtree format --query "select 1"
rtree format --sql "select 1"
rtree format < query.sql > formatted.sql
cat query.sql | rtree format

rtree query "SELECT 1"
rtree query -q "SELECT 1"
rtree query --query "SELECT 1"
rtree query --sql "SELECT 1"
rtree query < query.sql
cat query.sql | rtree query

Explicit stdin also works as a positional -, --sql -, --query -, or -q - for both commands.

Formatting preserves the complete response byte for byte; --json returns { "formatted": "..." }. Organization, cluster, and optional database use existing scope resolution. The shared stdin reader preserves whitespace. Formatting allows 120 seconds for the complete HTTP request; the API retains its 30-second formatting timeout, 50 MiB JSON input limit, and 100 MiB output limit. Multiple statements and literals are preserved, including inline INSERT VALUES payloads without completeness/schema validation. Errors emit no partial formatted SQL.

Bump CLI 0.6.14 → 0.6.15 in Cargo.toml and Cargo.lock.

Dependency: Platform #1468, inspected at 397dc652846ad5820073641c19301ea154289cce. The formatting endpoint must be deployed before this command can be used.

Validation:

  • cargo fmt --all -- --check; cargo test --locked: 208 passed, six existing real-Platform tests skipped locally.
  • cargo clippy --all-targets --locked: succeeded with pre-existing warnings.
  • Integration tests verify all SQL input forms on both commands, conflicting inputs, exact request bodies and scope, complete SQL/output, large stdin, API errors, and malformed responses.
  • Executable HTTP fixture proof: 20 command invocations, covering every inline form, actual file redirection, and cat pipes with implicit stdin and every explicit - form. SQL bytes, endpoints, scope, output, and generated help verified.
  • Formatter feature validation also covered an exact 10 MiB stdin round trip, active-request cancellation on SIGINT, and a response after 31 seconds. Against the existing local Platform #1468 stack: multiple statements, incomplete inline INSERT VALUES data, a 270,000-element IN list, and syntax errors.
  • Codex autoreview (--mode local --max-priority P3) and thermo-nuclear maintainability review: no actionable findings. TruffleHog clean.

Companion: MCP #32.


Note

Low Risk
CLI-only feature and input UX changes with mock integration tests; depends on a new platform endpoint but does not alter auth or query execution paths beyond shared SQL resolution.

Overview
Adds rtree format to pretty-print SQL via POST /v1/query-format (optional database scope), with plain stdout or --json, and a 120s HTTP timeout so upload/download does not eat the server’s formatting budget.

query and format now share richer SQL input: --sql / --query / -q, implicit or explicit stdin (-), and stdin content is sent without trimming so whitespace is preserved. The API client exposes post_with_timeout for configurable request deadlines.

Docs cover the new command and limits; integration tests exercise format, stdin, scopes, and errors. Version 0.6.14 → 0.6.15 (requires Platform /v1/query-format).

Reviewed by Cursor Bugbot for commit aadb16f. Bugbot is set up for automated code reviews on this repo. Configure here.

@rmorehig rmorehig changed the title Add native SQL query formatting command Add native SQL formatting with rtree format Oct 16, 2026
@rmorehig
rmorehig merged commit 4ed68db into main Oct 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant