Skip to content

Upgrade to oliphant 0.2.0 and wire up sqlc fmt for PostgreSQL - #4587

Merged
kyleconroy merged 1 commit into
mainfrom
claude/oliphant-upgrade-sqlc-fmt-x0krfk
Aug 27, 2026
Merged

Upgrade to oliphant 0.2.0 and wire up sqlc fmt for PostgreSQL#4587
kyleconroy merged 1 commit into
mainfrom
claude/oliphant-upgrade-sqlc-fmt-x0krfk

Conversation

@kyleconroy

Copy link
Copy Markdown
Collaborator

Upgrades oliphant from v0.1.0 to v0.2.0 and turns on sqlc fmt for the postgresql engine.

What's in oliphant 0.2.0

The release adds parser.ParseFile, which returns the parse tree together with the comment tokens the scanner already produces — from the same pass the parse makes over the input. That is exactly the contract sqlc fmt requires from an engine: statements and comments in one lexer pass, positioned in the same byte offsets the tree's location fields carry.

Changes

  • internal/engine/postgresql/parse.go: the PostgreSQL parser now implements ParseFile(io.Reader) (*ast.File, error), mirroring the SQLite engine's meyer-based template. oliphant's comment tokens become ast.Comment values (text, byte offsets, own-line flag), and the existing statement-span conventions — leading comments covered, pre-PG18 location semantics — are untouched. Parse now delegates to ParseFile.
  • internal/cmd/fmt.go: newQueryFormatter returns the PostgreSQL parser for postgresql configs. The engine already implemented format.Dialect, so ParseFile was the only missing piece.
  • Fingerprint belt: PostgreSQL brings a proof the other engines cannot offer — oliphant's pg_query-compatible fingerprint. fmt now recognizes an optional fingerprinter interface: where an engine implements Fingerprint, a formatted statement is only accepted when its fingerprint matches the original's, and falls back to the text as written otherwise. This sits on top of the existing reparse / comment-multiset / fixed-point checks and makes the documented "proven to survive formatting unchanged" contract literal for PostgreSQL.
  • Test data: the fmt/postgresql end-to-end case drops its "does not yet support the postgresql engine" stderr.txt; stdout.txt now commits the real fmt --diff golden output. Trailing and interior comments stay anchored (-- the primary lookup stays on the LIMIT 1; line, -- the primary key stays with its select-list item), and the deliberately long one-line SearchAuthors stays on one line, gofmt-style.

Testing

  • TestReplay/base/fmt/{postgresql,mysql,sqlite} pass.
  • TestFormat passes — it round-trips every PostgreSQL testdata case through the printer and compares pg_query fingerprints.
  • Full go test --tags=examples -timeout 20m ./... passes against live PostgreSQL and MySQL.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K8CZxjsrAjJsvGfZNrR7Gd


Generated by Claude Code

oliphant 0.2.0 adds parser.ParseFile, which returns the parse tree along
with the comment tokens its scanner already produces. That is exactly what
sqlc fmt needs from an engine, so the PostgreSQL parser now implements
ParseFile — Parse delegates to it, keeping the statement-span conventions
unchanged — and fmt formats postgresql query files.

PostgreSQL also brings a proof the other engines cannot offer: oliphant's
pg_query-compatible fingerprint. Where an engine implements Fingerprint,
fmt only accepts a formatted statement whose fingerprint matches the
original's, and falls back to the text as written otherwise.

The fmt/postgresql end-to-end case now commits its formatted diff instead
of an unsupported-engine notice.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K8CZxjsrAjJsvGfZNrR7Gd

Copy link
Copy Markdown
Collaborator Author

CI status on 71a6e6f: the only red check is build windows/amd64, and the failure is not this PR's — the job died during go mod download with a transient Go module proxy error (proxy.golang.org … stream ID 129; INTERNAL_ERROR; received from peer fetching github.com/ncruces/go-sqlite3-wasm/v3, a dependency this PR doesn't touch), before any code was built. The same module downloaded fine in the five sibling build jobs of the same run, and test (the full --tags=examples suite against live PostgreSQL and MySQL), vuln_check, and the other platform builds are all green. build linux/arm64 shows as cancelled only because fail-fast stopped it during post-job cleanup; its go build ./... step had already succeeded.

I don't have permission to re-run the failed jobs from here (the API returns 403), so this needs a "Re-run failed jobs" click on the workflow run from a maintainer. No code change is needed.


Generated by Claude Code

@kyleconroy
kyleconroy merged commit 55cfba4 into main Aug 27, 2026
18 of 20 checks passed
@kyleconroy
kyleconroy deleted the claude/oliphant-upgrade-sqlc-fmt-x0krfk branch August 27, 2026 17:17
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.

2 participants