feat: generate — :execrows/:execresult verbs + verb robustness - #28
Merged
Conversation
Widen the query analyzer, chosen by a leverage census of ~500 real annotated queries: the non-standard-verb bucket (:execrows, 71 uses in one corpus) was the single largest blocker, dwarfing outer joins/CTEs. - Recognize any `-- name: X :verb` header (was hard-coded to :one|:many|:exec) so an unknown verb is reported clearly instead of silently merging its SQL into the previous query — the root cause of the misleading "expected exactly one SQL statement" error. - Emit :execrows -> (int64, error) via ExecContext + RowsAffected(), and :execresult -> (sql.Result, error). - Reject pgx-only verbs (:copyfrom, :batchexec/many/one) and :execlastid with actionable errors instead of broken output. - Rename parameters that collide with a generated method's locals (e.g. a column named `result`) so the output always compiles. - Malformed `-- name:` headers fail loudly; prose comments that merely start with "-- name:" stay ordinary SQL. Golden output for :one/:many/:exec is byte-identical (regression-locked).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Widens
sequa generate's query analyzer — the coverage frontier a corpus census identified as highest-leverage.Census (real annotated queries): the non-standard-verb bucket was the single biggest blocker —
:execrowsalone is 71 uses in one corpus (~18% of 404 queries), dwarfing outer joins (3), CTEs (4), subqueries (7). So this PR does verbs first.Changes
-- name: X :verbheader. The regex was hard-coded to:one|:many|:exec, so an unknown verb (e.g.:execrows) failed to match and its SQL was silently merged into the previous query — surfacing the misleadingexpected exactly one SQL statementagainst the wrong query. Now every header is recognized and the verb is validated.:execrows→(int64, error)viaExecContext+result.RowsAffected().:execresult→(sql.Result, error)viaExecContext.:copyfrom,:batchexec/many/one) and:execlastidwith actionable errors (requires the pgx driver/use RETURNING with :one) instead of emitting broken code.result(orerr, etc.) is renamed (result2) so the generated body never redeclares its own locals. Also closes the pre-existing latent collision in:one/:many/:exec.-- name : X :exec) fails loudly; a prose comment that merely starts with-- name:stays ordinary SQL.Verification
:one/:many/:execoutput is byte-identical.verb_test.go(10 tests): the new verbs, the anti-silent-merge regression, verb rejection, the param-collision fix, and both malformed/prose header cases.resultcollision; over/under-broad malformed regex) were caught by an adversarial review pass and are regression-locked; the collision case compiles standalone.Outer joins,
SELECT *across joins, CTEs, and subqueries remain the next designed increments (tracked separately).