Skip to content

Add tests for PR #4646 (:iter query annotation) - #4647

Open
sgielen wants to merge 4 commits into
sqlc-dev:mainfrom
sgielen:feature/iter-2
Open

sgielen wants to merge 4 commits into
sqlc-dev:mainfrom
sgielen:feature/iter-2

Conversation

@sgielen

@sgielen sgielen commented Oct 16, 2026 •

Copy link
Copy Markdown

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 :iter at the same level as the other query types: one small case of its own, plus an :iter query 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 a DELETE … RETURNING, generated with emit_interface.
  • An :iter query in wrap_errors, prepared_queries and comment_godoc_db_argument.
  • invalid_queries_foo checks that :iter needs a RETURNING clause, like :one and :many.
  • The "missing query type" error now lists :iter.

MySQL and SQLite

  • An :iter query in wrap_errors (MySQL, SQLite), prepared_queries (MySQL) and sqlc_slice (MySQL).
  • TestIterAuthors in 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, break releases the connection, and a cancelled query's error comes back from the returned func.

One template change. The sqlc.slice branch of the shared queryCodeStdExec helper started its output with a newline. Every other command calls the helper right after an opening {, so the newline never showed. :iter calls 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 :iter method, its imports, and for prepared_queries the prepared statement.

🤖 Generated with Claude Code

sgielen and others added 4 commits October 16, 2026 18:57
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
sgielen marked this pull request as ready for review October 16, 2026 17:56
@sgielen sgielen changed the title Test the :iter query annotation Add tests for PR #4646 (:iter query annotation) Oct 16, 2026
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