Upgrade to oliphant 0.2.0 and wire up sqlc fmt for PostgreSQL - #4587
Conversation
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
|
CI status on 71a6e6f: the only red check is build windows/amd64, and the failure is not this PR's — the job died during 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 |
Upgrades oliphant from v0.1.0 to v0.2.0 and turns on
sqlc fmtfor thepostgresqlengine.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 contractsqlc fmtrequires 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 implementsParseFile(io.Reader) (*ast.File, error), mirroring the SQLite engine's meyer-based template. oliphant's comment tokens becomeast.Commentvalues (text, byte offsets, own-line flag), and the existing statement-span conventions — leading comments covered, pre-PG18 location semantics — are untouched.Parsenow delegates toParseFile.internal/cmd/fmt.go:newQueryFormatterreturns the PostgreSQL parser forpostgresqlconfigs. The engine already implementedformat.Dialect, soParseFilewas the only missing piece.fingerprinterinterface: where an engine implementsFingerprint, 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.fmt/postgresqlend-to-end case drops its "does not yet support the postgresql engine"stderr.txt;stdout.txtnow commits the realfmt --diffgolden output. Trailing and interior comments stay anchored (-- the primary lookupstays on theLIMIT 1;line,-- the primary keystays with its select-list item), and the deliberately long one-lineSearchAuthorsstays on one line, gofmt-style.Testing
TestReplay/base/fmt/{postgresql,mysql,sqlite}pass.TestFormatpasses — it round-trips every PostgreSQL testdata case through the printer and compares pg_query fingerprints.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