Skip to content

[yumin-xia] feat(wicked): generate opt-in Each readers - #24

Merged
Stumble merged 9 commits into
mainfrom
yumin-xia/many-each-hooks
Nov 11, 2026
Merged

Stumble merged 9 commits into
mainfrom
yumin-xia/many-each-hooks

Conversation

@Stumble

@Stumble Stumble commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

Generated :many methods collect every row before returning. Add opt-in -- -- each: true for SELECT reads so callers can validate, filter, aggregate, stream or bound their own collection without handwritten SQL plumbing.

The annotation generates XxxEach(ctx, params, visit) error beside the existing slice method. The typed visitor receives the effective query context and returns (more bool, err error): true continues, false stops consumption, and a non-nil error remains primary after cleanup.

Architecture and Key Decisions

  • Existing methods and the legacy Querier interface retain their exact signatures and behavior. Optional companions use a separate EachQuerier interface.
  • Each directly queries the DB, bypassing result-cache reads, fills and singleflight. Timeout, CountIntent and transaction/replica routing still apply. No wpgx change is needed.
  • Normal stop, ordinary errors and panic close/drain before the query's own cancellation. A late drain error after successful early stop is reported. Explicit caller cancellation may invalidate the connection/transaction.
  • Compiler-supplied statement facts reject opted-in mutations, data-changing or unsupported CTEs, SELECT INTO and missing safety metadata. Companion/helper/interface collisions fail generation.

CI also uncovered a pre-existing Go 1.26.10 standard-library vulnerability (GO-2026-6859). The build/release minimum and existing CI pins are updated to the Go 1.26.11 security patch; library dependencies and generated APIs are unchanged.

Risks and Remaining Work

Callbacks hold the connection and must respect the query context. Each shares the SQL operation/CountIntent label with the slice method; runtimes that measure through rows.Close include callback time, and explicit abort may appear as a context-canceled DB error under that label. Syntactic SELECT validation cannot prove function side-effect freedom. Each does not bound the allocation required to receive/decode the current row; SQL-level single-value protections and application policies remain explicit. Downstream adoption follows a generator release.

Breaking Changes

None. Without opt-in, eight downstream input snapshots regenerate byte-identically: 1,031 Go files, zero differences. Existing cache/invalidation, timeout and Dump/Load output is unchanged.

Database Migrations

None.

Verification

  • Root (Go 1.26.11): GOWORK=off GOMAXPROCS=2 go build -p=2 ./... and go test -p=2 -count=1 ./internal/cmd ./internal/codegen/wicked ./internal/compiler ./internal/sql/astutils ./internal/plugin passed.
  • Testdata module: full go build -p=2 ./... and go test -race -p=2 -count=1 ./wicked_compat/go ./wicked_many/go ./wicked_each/go passed.
  • Actual generated-method tests cover ordering, stop/error precedence, scan/source/close failures, cancellation/deadline/panic, nil/empty, retained rows, replicas, cache bypass and context lifetime. They run through the existing wicked CI entrypoint.
  • Runtime checks passed with wpgx v0.3.1, v0.3.4, v0.4.8, v0.4.9 and v0.5.0. Disposable PostgreSQL integration checks passed for same-transaction reuse after stop/error and connection replacement after explicit cancellation.
  • Legacy goldens were captured with the pre-change compiler, covering cache, scalar/struct params, mutations/invalidation, modifying CTEs and interface on/off. New fixture regeneration is clean. buf lint and git diff --check passed.
  • No full downstream service-stack E2E was requested. Final head e9467fc passes all active CI checks: full repository tests, bookstore compatibility/runtime contracts, six platform builds, protocol checks and govulncheck (10 success; 3 conditional language jobs skipped).

Merge Order

None. No runtime release dependency.

Related PRs

None. Implementation and review evidence: docs/changelogs/2026-11-11-add-many-each.md.

Independent Claude Code review explicitly endorses the design and accepts the complete implementation diff. Both agents reviewed final content; no actionable finding remains. The reviewer independently executed generator/fixture/runtime and selected consumer checks across implementation rounds, and inspected the author's broader PG/race/runtime-version/consumer evidence. This reconfirmation and its scope are recorded in the changelog.

@Stumble
Stumble merged commit 69cecc5 into main Nov 11, 2026
13 checks passed
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