Repository navigation
Conversation
A :iter query generates a method returning an iter.Seq over the query's rows, plus a function returning the query's error once the loop is done. The PostgreSQL authors example shows its use.
A case of its own for the stdlib and pgx templates, and an :iter query in the cases for wrap_errors, emit_prepared_queries and emit_methods_with_db_argument, as the other query types have. invalid_queries_foo covers :iter without a RETURNING clause, and the "missing query type" error now lists :iter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An :iter query in the wrap_errors, emit_prepared_queries and sqlc_slice cases for MySQL and SQLite, and a runtime test in the SQLite authors example, covering the stdlib template against a live database. queryCodeStdExec no longer starts with a newline when it rewrites a query for sqlc.slice, which left a blank line inside :iter methods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sgielen
marked this pull request as ready for review
October 16, 2026 17:56
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.
This is a stacked PR on top of #4646, which adds
:iter. This PR contains further tests, to keep that PR lean and reviewable.Because Github doesn't do stacked PRs across a fork, it looks like this PR also contains #4646's changes. In order to review this commit I'd advise to look at the individual commits:
This adds test coverage for
:iterat the same level as the other query types: one small case of its own, plus an:iterquery in the existing cases for each Go option that changes the generated method.PostgreSQL
iter/postgresql/{stdlib,pgx/v5}: a struct result with a SQL comment, a scalar result with a parameter, and aDELETE … RETURNING, generated withemit_interface.:iterquery inwrap_errors,prepared_queriesandcomment_godoc_db_argument.invalid_queries_foochecks that:iterneeds aRETURNINGclause, like:oneand:many.:iter.MySQL and SQLite
:iterquery inwrap_errors(MySQL, SQLite),prepared_queries(MySQL) andsqlc_slice(MySQL).TestIterAuthorsin the SQLite authors example. It runs the stdlib template against a real database, like the PostgreSQL authors test in Add the :iter query annotation #4646 does for pgx: the query only runs once ranging starts, ranging a second time reports an error,breakreleases the connection, and a cancelled query's error comes back from the returned func.One template change. The
sqlc.slicebranch of the sharedqueryCodeStdExechelper started its output with a newline. Every other command calls the helper right after an opening{, so the newline never showed.:itercalls it after a statement, where it left a blank line. The branch now trims it, and no other golden changes.The goldens of the existing cases only gain lines: the
:itermethod, its imports, and forprepared_queriesthe prepared statement.🤖 Generated with Claude Code