diff --git a/.github/workflows/wicked.yml b/.github/workflows/wicked.yml index b982ea614f..41c8317b7c 100644 --- a/.github/workflows/wicked.yml +++ b/.github/workflows/wicked.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v6 with: repository: Stumble/bookstore - ref: 2a7f7e396451821a8fe3054eb265037b830af68d + ref: 89b3fbc09bf274e563722c3f582f5c3ac4bca3ec path: bookstore - name: Check generated API and code working-directory: bookstore diff --git a/GUIDE.md b/GUIDE.md index b1152466e7..40ab138d46 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -389,6 +389,26 @@ ERROR: orders/GetOrderByID does not have a timeout option ERROR: *pkg*/*name* does not have a timeout option ``` +The `timeout` is the query's database timeout: it bounds how long the query +holds a database connection, not how long it waits for one. Generated code +passes it to `wpgx.WithDBTimeout`, so it requires a wpgx release with that +function. At run time: + +- On a pool connection the query first waits for a connection, at most the + larger of `timeout` and the pool's `AcquireTimeout` (wpgx default 2s). +- The `timeout` starts once the query has a connection, or at the call inside a + transaction, and covers reading its rows (an `each` visitor included). +- Cache lookups are bounded by the Redis client's own timeouts, with dcache + v0.3.0+ and Redis single flight off (its default). With Redis single flight, + an unresponsive Redis is retried until the caller's context ends, so callers + need a deadline. +- The caller's context deadline and cancellation always apply. + +Errors match `wpgx.ErrAcquireTimeout` or `wpgx.ErrDBTimeout`, and +`context.DeadlineExceeded`. Before this release the `timeout` started when the +method was called and also covered the cache lookup and the wait for a +connection. + Here is an example of listing all books of a category, with using id as the cursor for pagination. @@ -471,9 +491,10 @@ the original `Querier` method set stays the same. `each: false` disables a companion. The new annotation requires a generator release supporting it. The consumer is synchronous, holds the connection, and runs under the query -context/deadline. It must respect that context and cannot reenter the same -active transaction connection. Normal stop, error and panic close/drain rows -before the query's own context is cancelled. A drain failure after normal stop +context, which carries the database timeout once the query has a connection. +It must respect that context and cannot reenter the same active transaction +connection. Normal stop, error and panic close/drain rows before the query's +own context is cancelled. A drain failure after normal stop is returned; a prior callback/scan error remains primary. Panic propagates after cleanup. To stop receiving remaining data, cancel a caller-created context scoped to this query. Explicit cancellation or timeout may close the physical @@ -906,7 +927,9 @@ The code of wpgx is very simple, the best way to understand it is to read its so + {appName}_wpgx_conn_pool{name="max_conns/total_conns/...."}: connection pool gauges. + {appName}_wpgx_request_total{name="$queryName"}: number of DB hits for each query. -+ {appName}_wpgx_latency_milliseconds{name="$queryName"}: histogram of SQL execution duration. ++ {appName}_wpgx_latency_milliseconds{name="$queryName"}: histogram of the whole call, including the wait for a connection. ++ wpgx_acquire_wait_milliseconds, wpgx_db_latency_milliseconds and wpgx_timeout_total split + the wait for a connection from database time; see the wpgx README. ### Open Telemetry diff --git a/docs/changelogs/2026-11-20-db-timeout-after-acquire.md b/docs/changelogs/2026-11-20-db-timeout-after-acquire.md new file mode 100644 index 0000000000..9fd441faaf --- /dev/null +++ b/docs/changelogs/2026-11-20-db-timeout-after-acquire.md @@ -0,0 +1,124 @@ +# feat: pass query timeouts to wpgx as database timeouts + +Local record. The complete design, decisions and risks are in the primary +record, Stumble/wpgx `docs/changelogs/2026-11-20-db-timeout-after-acquire.md`. + +## 1. Background and Current State + +- Every wicked query requires `-- -- timeout: T`. Generated methods start + `context.WithTimeout(ctx, T)` at the top, so T also covers the dcache lookup + and the wait for a pooled connection (`queryCode.tmpl`, `copyfromCopy.tmpl`). +- The opt-in Each companion (v2.5.0) runs the visitor under that context and + checks it after each row and after closing. +- Fixtures under `internal/endtoend/testdata` compile against wpgx v0.3.1; the + `wicked` CI job regenerates Stumble/bookstore at a pinned commit and requires + no diff, then runs its runtime contracts. + +## 2. Problem Model and End-to-End Behavior + +- B1 — Every generated method (`:one`, `:many`, `:exec`, `:execrows`, + `:execresult`, `:copyfrom`, Each) passes T to + `wpgx.WithDBTimeout(ctx, "", T)` instead of starting its own + deadline. wpgx starts T once the statement has a connection (B1/B2 of the + primary record). Annotation syntax, validation and method signatures are + unchanged. +- B2 — dcache receives the caller's context (plus the timeout value), so cache + lookups and fills are bounded by the Redis client's timeouts, not by T. +- B3 — Each visitors receive the statement context from wpgx rows (falling + back to the method context; `qctx` is reassigned, so no new local name can + collide with a SQL parameter). Each reports through `wpgx.StatementErr`: an + ended statement context, a visitor's error that is that context's deadline, + and, after closing the rows, a database timeout that expired while reading or + draining buffered rows all match `wpgx.ErrDBTimeout` (as the previous Each + failed when its query context expired). Other visitor and row errors stay + primary; the caller's context is checked last. +- B4 — Generated files import `github.com/stumble/wpgx`; regenerated code + needs a wpgx release with `WithDBTimeout` (compile-time check). +- F1 — Missing timeouts still fail generation. +- F2 — A SQL parameter named `wpgx` is generated as `wpgx_` (reserved), so it + cannot shadow the package the method bodies now call. +- B2 precondition: the Redis-client bound holds with dcache v0.3.0+ and Redis + single flight off (default); see R6 of the primary record. +- Compatibility: regenerating changes generated code by design (owner chose + the new semantics as the default of this minor release). Old generated code + keeps working with new wpgx. + +## 3. Research, Findings, and Architecture Decision + +See the primary record (D1–D5, R1–R5). Local decisions: + +- D6 — Keep the template variable `qctx` so the diff stays small and + readable; it now carries only the timeout value. +- D7 — Each discovers the statement context through an anonymous + `interface{ Context() context.Context }` assertion, so fake queriers in + tests keep working and no new exported API is needed in generated code. + +## 4. Implementation Design + +- `internal/codegen/wicked/templates/wpgx/queryCode.tmpl`: replace the five + `context.WithTimeout` blocks and the Each body. +- `internal/codegen/wicked/templates/wpgx/copyfromCopy.tmpl`: same for + `:copyfrom`. +- `internal/codegen/wicked/imports.go`: import wpgx in query and copyfrom files. +- Regenerate `internal/endtoend/testdata/wicked_*` and bump the testdata + module's wpgx; update the Each runtime contract tests; add a PostgreSQL + runtime check for the timeout boundary next to the existing optional Each + check. +- `.github/workflows/wicked.yml`: point the bookstore job at the bookstore + commit regenerated with this change. +- `GUIDE.md`: document the timeout semantics. + +### Serial Implementation Checklist + +- [x] Templates and imports. +- [x] Regenerate fixtures; bump the testdata wpgx; update/add runtime tests. +- [x] Guide. +- [x] Bookstore pin (commit 89b3fbc, published with this branch). + +## 5. Verification and E2E Design + +E2E Required: no. + +Commands (repository root, GOMAXPROCS=2, GOWORK=off unless noted): + +- `go build -p=1 -ldflags "-X github.com/sqlc-dev/sqlc/internal/info.Version=v2.4.0-dev-wicked-fork" -o ../sqlc-new ./cmd/sqlc` (as CI's `make build COMMIT_HASH=v2.4.0-dev`) and a default-version build for fixtures. +- `go test -p=1 -count=1 ./internal/codegen/wicked ./internal/cmd`. +- `go test -p=1 -count=1 -run 'TestReplay/base/wicked' ./internal/endtoend`. +- In `internal/endtoend/testdata`: `go build ./...` (`make build-endtoend`) and + `go test ./wicked_compat/go`, plus the PostgreSQL checks with + `SQLC_EACH_TEST_DSN`. +- Bookstore: `make sqlc`, `make sqlc-verify`, `git diff --exit-code -- pkg/repos`, + `go test -race -count=1 -p 1 ./pkg/usecases`. + +## 6. Human Decisions and Interaction + +See the primary record, section 6. + +## 7. Outcome and Evidence + +- Result: B1–B4 and F1–F2 as specified; generated code requires wpgx with + `WithDBTimeout`/`StatementErr` (pinned to the wpgx branch commit + `v0.5.2-0.20261120053742-4b29cac2136d` in the testdata module until tagged). +- Deviations (reviewed): Each reassigns `qctx` instead of declaring `vctx` + (R1-05); `wpgx` is a reserved identifier; Each reports through + `wpgx.StatementErr` (R2-02). The testdata module was already not tidy at the + base, so only `go get` was applied. +- Verification on the final content (`GOMAXPROCS=2`, `-p 1`): + - Builds: `go build -p=1 -ldflags "-X github.com/sqlc-dev/sqlc/internal/info.Version=v2.4.0-dev-wicked-fork" -o ../sqlc-new ./cmd/sqlc` and the default-label `../sqlc-fixture`; fixtures regenerated with the latter. + - `GOWORK=off go test -p=1 -count=1 ./internal/codegen/wicked ./internal/cmd`: pass. + - `GOWORK=off go test -p=1 -count=1 -run 'TestReplay/base/' ./internal/endtoend` with this repository's `sqlc-gen-json` on PATH: pass (a stale `~/go/bin/sqlc-gen-json` from another build fails `process_plugin_sqlc_gen_json` independently of this change); `-run 'TestReplay/base/wicked'`: pass. + - `internal/endtoend/testdata` with `GOWORK=off CGO_ENABLED=0`: `go build ./...` pass; `SQLC_EACH_TEST_DSN=postgres://…@127.0.0.1:55491/sqlc_test go test -race -count=1 ./wicked_compat/go`: pass, including `TestGeneratedTimeoutPostgres` (5 subtests) and `TestGeneratedEachPostgres`. + - Mutation checks: the v2.5.0 generated Each fixture fails the timeout test; reverting the two `StatementErr` lines fails both new Each regressions. + - Wicked CI bookstore job reproduced on a clean clone of bookstore 89b3fbc: regenerate, `sqlc diff`, no diff, build. +- Cross-agent review: primary record section 7 (Codex session + `5e2002b6-dea5-4c53-96c9-cde8cdd6a84b`, rounds 1–5, final ACCEPT of + 5291d2071 with wpgx 4b29cac and bookstore 89b3fbc). Later changes here are + record-only. +- Not run locally: the full CI suite (`go test --tags=examples ./...` needs + MySQL and PostgreSQL services); CI runs it. + +## 8. Remaining Work + +- Before merge: after wpgx is tagged and the bookstore PR merged, bump the + testdata wpgx pin to the tag and point `.github/workflows/wicked.yml` at the + merged bookstore commit; then tag a new sqlc minor. diff --git a/internal/codegen/wicked/imports.go b/internal/codegen/wicked/imports.go index 1bc34b36f5..5e2cc65164 100644 --- a/internal/codegen/wicked/imports.go +++ b/internal/codegen/wicked/imports.go @@ -393,6 +393,8 @@ func (i *importer) queryImports(filename string) fileImports { } } pkg[ImportSpec{Path: "github.com/rs/zerolog/log"}] = struct{}{} + // Generated methods pass their timeout to wpgx.WithDBTimeout. + pkg[ImportSpec{Path: "github.com/stumble/wpgx"}] = struct{}{} return sortedImports(std, pkg) } @@ -421,6 +423,7 @@ func (i *importer) copyfromImports() fileImports { std["context"] = struct{}{} std["time"] = struct{}{} + pkg[ImportSpec{Path: "github.com/stumble/wpgx"}] = struct{}{} if i.Options.SqlDriver == opts.SQLDriverGoSQLDriverMySQL { std["io"] = struct{}{} std["fmt"] = struct{}{} diff --git a/internal/codegen/wicked/options_test.go b/internal/codegen/wicked/options_test.go index 65fa66b2c2..58dae38b6b 100644 --- a/internal/codegen/wicked/options_test.go +++ b/internal/codegen/wicked/options_test.go @@ -133,3 +133,14 @@ func TestEachVisitorNames(t *testing.T) { } } } + +func TestGeneratedPackageNamesAreReserved(t *testing.T) { + // Generated method bodies call the wpgx package, so a parameter must not + // shadow it. + if got := escape("wpgx"); got != "wpgx_" { + t.Fatalf("escape(wpgx)=%s", got) + } + if got := escape("vctx"); got != "vctx" { + t.Fatalf("escape(vctx)=%s", got) + } +} diff --git a/internal/codegen/wicked/reserved.go b/internal/codegen/wicked/reserved.go index 94494f81b6..261cbb93cc 100644 --- a/internal/codegen/wicked/reserved.go +++ b/internal/codegen/wicked/reserved.go @@ -61,6 +61,9 @@ func IsReserved(s string) bool { return true case "q": return true + case "wpgx": + // Generated methods call the wpgx package. + return true default: return false } diff --git a/internal/codegen/wicked/templates/wpgx/copyfromCopy.tmpl b/internal/codegen/wicked/templates/wpgx/copyfromCopy.tmpl index 026a53f88f..6f8d09c2a0 100644 --- a/internal/codegen/wicked/templates/wpgx/copyfromCopy.tmpl +++ b/internal/codegen/wicked/templates/wpgx/copyfromCopy.tmpl @@ -39,8 +39,7 @@ func (r iteratorFor{{.MethodName}}) Err() error { {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) (int64, error) { {{- if gt .Option.Timeout.Milliseconds 0 }} - ctx, cancel := context.WithTimeout(ctx, time.Millisecond * {{.Option.Timeout.Milliseconds}}) - defer cancel() + ctx = wpgx.WithDBTimeout(ctx, "{{.UniqueLabel}}", time.Millisecond * {{.Option.Timeout.Milliseconds}}) {{- end}} q.db.CountIntent("{{.UniqueLabel}}") return q.db.WCopyFrom(ctx, "{{.UniqueLabel}}", {{.TableIdentifierAsGoSlice}}, {{.Arg.ColumnNamesAsGoSlice}}, &iteratorFor{{.MethodName}}{rows: {{.Arg.Name}}}) diff --git a/internal/codegen/wicked/templates/wpgx/queryCode.tmpl b/internal/codegen/wicked/templates/wpgx/queryCode.tmpl index 38679fc11d..8b4322a802 100644 --- a/internal/codegen/wicked/templates/wpgx/queryCode.tmpl +++ b/internal/codegen/wicked/templates/wpgx/queryCode.tmpl @@ -48,8 +48,7 @@ func (q *ReadOnlyQueries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (* func _{{.MethodName}}(ctx context.Context, q {{.ConnType}}, {{.Arg.Pair}} {{.InvalidateArgs}}) (*{{.Ret.Type}}, error) { {{- if gt .Option.Timeout.Milliseconds 0 }} - qctx, cancel := context.WithTimeout(ctx, time.Millisecond * {{.Option.Timeout.Milliseconds}}) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "{{.UniqueLabel}}", time.Millisecond * {{.Option.Timeout.Milliseconds}}) {{- end}} {{- if .CountIntent }} q.GetConn().CountIntent("{{.UniqueLabel}}") @@ -138,8 +137,7 @@ func (q *ReadOnlyQueries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([ func _{{.MethodName}}(ctx context.Context, q {{.ConnType}}, {{.Arg.Pair}} {{.InvalidateArgs}}) ([]{{.Ret.Type}}, error) { {{- if gt .Option.Timeout.Milliseconds 0 }} - qctx, cancel := context.WithTimeout(ctx, time.Millisecond * {{.Option.Timeout.Milliseconds}}) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "{{.UniqueLabel}}", time.Millisecond * {{.Option.Timeout.Milliseconds}}) {{- end}} {{- if .CountIntent }} q.GetConn().CountIntent("{{.UniqueLabel}}") @@ -233,7 +231,8 @@ func _{{.MethodName}}(ctx context.Context, q {{.ConnType}}, {{.Arg.Pair}} {{.Inv // It directly queries the DB, bypassing the slice method's result cache. // Return true to continue or false to stop the whole read; to skip a row, // omit its output and return true. Errors are returned after rows are closed. -// The query timeout covers the synchronous visitor and draining. The visitor +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor // must respect ctx and must not query again on the same active connection. // Normal stop and visitor error drain by default; cancel a query-specific // caller context to abort transfer, which may invalidate its connection/tx. @@ -252,28 +251,33 @@ func _{{.MethodName}}Each(ctx context.Context, q CacheQuerierConn, {{if .Arg.Pai if {{.EachVisitName}} == nil { return fmt.Errorf("{{.MethodName}}Each: nil visitor") } - qctx, cancel := context.WithTimeout(ctx, time.Millisecond * {{.Option.Timeout.Milliseconds}}) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "{{.UniqueLabel}}", time.Millisecond * {{.Option.Timeout.Milliseconds}}) {{if .CountIntent}}q.GetConn().CountIntent("{{.UniqueLabel}}"){{end}} rows, err := q.GetConn().WQuery(qctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) if err != nil { return err } defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } for rows.Next() { - if err := qctx.Err(); err != nil { return err } + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } var eachRow *{{.Ret.Type}} = new({{.Ret.Type}}) if err := rows.Scan({{.EachScan}}); err != nil { return err } more, err := {{.EachVisitName}}(qctx, *eachRow) - if err != nil { return err } - if err := qctx.Err(); err != nil { return err } + if err != nil { return wpgx.StatementErr(qctx, err) } + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } if !more { break } } // Close may drain pending results and surface a server error after a - // successful early stop. It must run before checking Err and cancelling. + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. rows.Close() - if err := rows.Err(); err != nil { return err } - return qctx.Err() + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { return err } + return ctx.Err() } {{end}} {{end}} @@ -283,8 +287,7 @@ func _{{.MethodName}}Each(ctx context.Context, q CacheQuerierConn, {{if .Arg.Pai {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) error { {{- if gt .Option.Timeout.Milliseconds 0 }} - qctx, cancel := context.WithTimeout(ctx, time.Millisecond * {{.Option.Timeout.Milliseconds}}) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "{{.UniqueLabel}}", time.Millisecond * {{.Option.Timeout.Milliseconds}}) {{- end}} _, err := q.db.WExec(qctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) if err != nil { @@ -331,8 +334,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) (int64, error) { {{- if gt .Option.Timeout.Milliseconds 0 }} - qctx, cancel := context.WithTimeout(ctx, time.Millisecond * {{.Option.Timeout.Milliseconds}}) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "{{.UniqueLabel}}", time.Millisecond * {{.Option.Timeout.Milliseconds}}) {{- end}} result, err := q.db.WExec(qctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) if err != nil { @@ -379,8 +381,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) (pgconn.CommandTag, error) { {{- if gt .Option.Timeout.Milliseconds 0 }} - qctx, cancel := context.WithTimeout(ctx, time.Millisecond * {{.Option.Timeout.Milliseconds}}) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "{{.UniqueLabel}}", time.Millisecond * {{.Option.Timeout.Milliseconds}}) {{- end}} rv, err := q.db.WExec(qctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) if err != nil { diff --git a/internal/endtoend/testdata/go.mod b/internal/endtoend/testdata/go.mod index fe50756b30..ec6eb0cae0 100644 --- a/internal/endtoend/testdata/go.mod +++ b/internal/endtoend/testdata/go.mod @@ -1,18 +1,16 @@ module github.com/sqlc-dev/sqlc/endtoend -go 1.24.0 - -toolchain go1.24.7 +go 1.26.0 require ( github.com/go-sql-driver/mysql v1.7.0 github.com/gofrs/uuid v4.0.0+incompatible - github.com/google/uuid v1.3.0 + github.com/google/uuid v1.6.0 github.com/hexon/mysqltsv v0.1.0 github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853 github.com/jackc/pgtype v1.6.2 github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904 - github.com/jackc/pgx/v5 v5.8.0 + github.com/jackc/pgx/v5 v5.11.0 github.com/lib/pq v1.9.0 github.com/sqlc-dev/pqtype v0.2.0 github.com/sqlc-dev/sqlc-testdata v1.0.0 @@ -22,11 +20,11 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/coocood/freecache v1.2.3 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/friendsofgo/errors v0.9.2 // indirect - github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-redis/redis/v8 v8.11.5 // indirect github.com/golang/protobuf v1.5.3 // indirect @@ -37,30 +35,34 @@ require ( github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/kelseyhightower/envconfig v1.4.0 // indirect - github.com/klauspost/compress v1.15.14 // indirect - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect + github.com/klauspost/compress v1.20.1 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pgvector/pgvector-go v0.1.1 // indirect - github.com/prometheus/client_golang v1.16.0 // indirect - github.com/prometheus/client_model v0.3.0 // indirect - github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.10.1 // indirect - github.com/rs/zerolog v1.28.0 // indirect + github.com/prometheus/client_golang v1.25.0 // indirect + github.com/prometheus/client_model v0.6.3 // indirect + github.com/prometheus/common v0.72.0 // indirect + github.com/prometheus/procfs v0.22.0 // indirect + github.com/rs/zerolog v1.35.1 // indirect github.com/satori/go.uuid v1.2.0 // indirect github.com/stumble/dcache v0.1.3 // indirect - github.com/stumble/wpgx v0.3.1 // indirect + github.com/stumble/wpgx v0.5.2-0.20261120053742-4b29cac2136d // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/volatiletech/inflect v0.0.1 // indirect github.com/volatiletech/randomize v0.0.1 // indirect github.com/volatiletech/strmangle v0.0.1 // indirect - go.opentelemetry.io/otel v1.12.0 // indirect - go.opentelemetry.io/otel/trace v1.12.0 // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/sync v0.17.0 // indirect - golang.org/x/sys v0.15.0 // indirect - golang.org/x/text v0.29.0 // indirect + go.opentelemetry.io/auto/sdk v1.2.1 // indirect + go.opentelemetry.io/otel v1.47.0 // indirect + go.opentelemetry.io/otel/log v1.47.0 // indirect + go.opentelemetry.io/otel/metric v1.47.0 // indirect + go.opentelemetry.io/otel/trace v1.47.0 // indirect + golang.org/x/crypto v0.56.0 // indirect + golang.org/x/sync v0.24.0 // indirect + golang.org/x/sys v0.48.0 // indirect + golang.org/x/text v0.42.0 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect - google.golang.org/protobuf v1.30.0 // indirect + google.golang.org/protobuf v1.36.12 // indirect ) diff --git a/internal/endtoend/testdata/go.sum b/internal/endtoend/testdata/go.sum index 0698936eee..0c73d4fc36 100644 --- a/internal/endtoend/testdata/go.sum +++ b/internal/endtoend/testdata/go.sum @@ -4,6 +4,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/coocood/freecache v1.2.3 h1:lcBwpZrwBZRZyLk/8EMyQVXRiFl663cCuMOrjCALeto= @@ -22,6 +24,8 @@ github.com/friendsofgo/errors v0.9.2/go.mod h1:yCvFW5AkDIL9qn7suHVLiI/gH228n7PC4 github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= +github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= @@ -42,6 +46,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hexon/mysqltsv v0.1.0 h1:48wYQlsPH8ZEkKAVCdsOYzMYAlEoevw8ZWD8rqYPdlg= github.com/hexon/mysqltsv v0.1.0/go.mod h1:p3vPBkpxebjHWF1bWKYNcXx5pFu+yAG89QZQEKSvVrY= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= @@ -104,6 +110,8 @@ github.com/jackc/pgx/v5 v5.7.0 h1:FG6VLIdzvAPhnYqP14sQ2xhFLkiUQHCs6ySqO91kF4g= github.com/jackc/pgx/v5 v5.7.0/go.mod h1:awP1KNnjylvpxHuHP63gzjhnGkI1iw+PMoIwvoleN/8= github.com/jackc/pgx/v5 v5.8.0 h1:TYPDoleBBme0xGSAX3/+NujXXtpZn9HBONkQC7IEZSo= github.com/jackc/pgx/v5 v5.8.0/go.mod h1:QVeDInX2m9VyzvNeiCJVjCkNFqzsNb43204HshNSZKw= +github.com/jackc/pgx/v5 v5.11.0 h1:IzBBtyK9AHqf98cctWFifYSci2hgQR/cd56wB4p+ogg= +github.com/jackc/pgx/v5 v5.11.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= @@ -116,6 +124,8 @@ github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.15.14 h1:i7WCKDToww0wA+9qrUZ1xOjp218vfFo3nTU6UHp+gOc= github.com/klauspost/compress v1.15.14/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ= +github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -133,6 +143,8 @@ github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= @@ -140,8 +152,12 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/pgvector/pgvector-go v0.1.1 h1:kqJigGctFnlWvskUiYIvJRNwUtQl/aMSUZVs0YWQe+g= github.com/pgvector/pgvector-go v0.1.1/go.mod h1:wLJgD/ODkdtd2LJK4l6evHXTuG+8PxymYAVomKHOWac= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -151,12 +167,20 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= +github.com/prometheus/client_golang v1.25.0 h1:cDtW1TcFsMi1RJc8khwCKB4VhzwV04aKqbYtNOXuiK0= +github.com/prometheus/client_golang v1.25.0/go.mod h1:j2X/4/kaQHLPnmyEU8zjmkndo1T317VpCIQEml8LTKk= github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= +github.com/prometheus/client_model v0.6.3 h1:O0jaTVAYNxTHYInEPFJt5I3+sN8zqBtVMPTB1qyxiEo= +github.com/prometheus/client_model v0.6.3/go.mod h1:gpN5P9S7Rr6Yr92PiQ+Ixvhf6JZEkF1dnxsYL2aPBEM= github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= +github.com/prometheus/common v0.72.0 h1:tAYsE+sPJxIncDAobm4H5aQjmox9ZxEIIqPbiffa8G4= +github.com/prometheus/common v0.72.0/go.mod h1:77NWqAQ2tXT7BIK40qjJdw5Acrsrg1TlHAnsQi3i6mk= github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= +github.com/prometheus/procfs v0.22.0 h1:6q9+/JL9IKAPbCmBrv9n5O5Ty3NKnciV5X7YGw0oics= +github.com/prometheus/procfs v0.22.0/go.mod h1:CvmFr/GVhIjIvWJZW3tgkODBQMRIf0EyWMQLHCHab58= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= @@ -164,6 +188,8 @@ github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OK github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= +github.com/rs/zerolog v1.35.1 h1:m7xQeoiLIiV0BCEY4Hs+j2NG4Gp2o2KPKmhnnLiazKI= +github.com/rs/zerolog v1.35.1/go.mod h1:EjML9kdfa/RMA7h/6z6pYmq1ykOuA8/mjWaEvGI+jcw= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= @@ -189,6 +215,8 @@ github.com/stumble/dcache v0.1.3 h1:ONN+Y65XgOe/tZ7Xnu5keS58oDX3KFjs5xqTk+mJG7s= github.com/stumble/dcache v0.1.3/go.mod h1:NRYV3jq62VEFw0SleYWHK5y6nONZ+LFnLXTo927ilVk= github.com/stumble/wpgx v0.3.1 h1:u56Xcj8gVBQSyk+nEf03HVqm3XUaytjsEjcEdDdkkXM= github.com/stumble/wpgx v0.3.1/go.mod h1:NzglxY/rDtz4lnR3CdP5HpMgL49Edq9Iftm9H6OKwEc= +github.com/stumble/wpgx v0.5.2-0.20261120053742-4b29cac2136d h1:pbfcjUEfEmEWvlMiPY05C230gBezNBpjZ2aEJ+rV2fc= +github.com/stumble/wpgx v0.5.2-0.20261120053742-4b29cac2136d/go.mod h1:8OzdIiJKnIXvnyF1iAjRCxkwQ6Qx1urY+cmGga0bSJE= github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc= @@ -203,10 +231,20 @@ github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xu github.com/volatiletech/strmangle v0.0.1 h1:UKQoHmY6be/R3tSvD2nQYrH41k43OJkidwEiC74KIzk= github.com/volatiletech/strmangle v0.0.1/go.mod h1:F6RA6IkB5vq0yTG4GQ0UsbbRcl3ni9P76i+JrTBKFFg= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/otel v1.12.0 h1:IgfC7kqQrRccIKuB7Cl+SRUmsKbEwSGPr0Eu+/ht1SQ= go.opentelemetry.io/otel v1.12.0/go.mod h1:geaoz0L0r1BEOR81k7/n9W4TCXYCJ7bPO7K374jQHG0= +go.opentelemetry.io/otel v1.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM= +go.opentelemetry.io/otel v1.47.0/go.mod h1:8wS9O2qfXrYrzp6hIF/HOYJJf/wIhFPhR2xLuP+iXQU= +go.opentelemetry.io/otel/log v1.47.0 h1:cOTS1CcLbSQeZKanGJ+0JpF/+t4PELi3O3bbl2lqCcI= +go.opentelemetry.io/otel/log v1.47.0/go.mod h1:9byitSQ5pLC6PpqwGXjqdMKya6ZTswHRZh2vvXT33nw= +go.opentelemetry.io/otel/metric v1.47.0 h1:4PptaldXx3Eat1XjMZ68pPJEs5wrhlemctZE9a3UdWY= +go.opentelemetry.io/otel/metric v1.47.0/go.mod h1:ADGSXxRrXM6bjbvLo535EstVFlPpPYZm4LBKixjDHwU= go.opentelemetry.io/otel/trace v1.12.0 h1:p28in++7Kd0r2d8gSt931O57fdjUyWxkVbESuILAeUc= go.opentelemetry.io/otel/trace v1.12.0/go.mod h1:pHlgBynn6s25qJ2szD+Bv+iwKJttjHSI3lUAyf0GNuQ= +go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM= +go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= @@ -228,6 +266,8 @@ golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.56.0 h1:GUh5Ii4J5jtcseSMiRqr1jXCNHoxjeV9Fmekc2oLy6Y= +golang.org/x/crypto v0.56.0/go.mod h1:OMW5y6CY9l38uPLmxU6l6pwcXp1obtLo3e6gT7gQR2I= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -238,6 +278,8 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA= +golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -250,8 +292,11 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= +golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= @@ -264,6 +309,8 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= +golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= +golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= @@ -282,6 +329,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= +google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/internal/endtoend/testdata/wicked_compat/go/each_runtime_test.go b/internal/endtoend/testdata/wicked_compat/go/each_runtime_test.go index c7fa08e91d..7dac38dbf9 100644 --- a/internal/endtoend/testdata/wicked_compat/go/each_runtime_test.go +++ b/internal/endtoend/testdata/wicked_compat/go/each_runtime_test.go @@ -22,10 +22,17 @@ type eachRows struct { closed bool closeCanceled bool ctx context.Context + cancel context.CancelFunc scanErr, sourceErr, closeErr, finalErr error failAfter int } +// stmtEachRows are rows like wpgx returns under a database timeout: they carry +// the statement context, which closing the rows cancels. +type stmtEachRows struct{ *eachRows } + +func (r stmtEachRows) Context() context.Context { return r.ctx } + func (r *eachRows) Close() { if r.closed { return @@ -38,6 +45,9 @@ func (r *eachRows) Close() { if r.finalErr == nil { r.finalErr = r.ctx.Err() } + if r.cancel != nil { + r.cancel() + } } func (r *eachRows) Err() error { return r.finalErr } func (r *eachRows) Next() bool { @@ -75,7 +85,10 @@ func (*eachRows) Conn() *pgx.Conn { return nil } func (*eachRows) TypeMap() *pgtype.Map { return nil } type eachConn struct { - rows *eachRows + rows *eachRows + // statementTimeout makes WQuery return stmtEachRows whose context has this + // timeout; zero returns plain rows. + statementTimeout time.Duration calls int intents []string name string @@ -93,6 +106,10 @@ func (c *eachConn) WQuery(ctx context.Context, name, sql string, args ...any) (p if err := ctx.Err(); err != nil { return nil, err } + if c.statementTimeout > 0 { + c.rows.ctx, c.rows.cancel = context.WithTimeout(ctx, c.statementTimeout) + return stmtEachRows{c.rows}, nil + } return c.rows, nil } func (*eachConn) WQueryRow(context.Context, string, string, ...any) pgx.Row { @@ -108,7 +125,7 @@ func (*eachConn) WCopyFrom(context.Context, string, pgx.Identifier, []string, pg func (*eachConn) PostExec(func() error) error { panic("unexpected PostExec") } func newEachConn() *eachConn { - return &eachConn{rows: &eachRows{data: []eachgen.Book{ + return &eachConn{statementTimeout: time.Minute, rows: &eachRows{data: []eachgen.Book{ {ID: 1, Value: []byte("one")}, {ID: 2, Value: []byte("two")}, {ID: 3, Value: []byte("three")}, @@ -124,7 +141,7 @@ func TestGeneratedEachVisitsAndOwnsLifecycle(t *testing.T) { var visitCtx context.Context visit := func(ctx context.Context, row eachgen.Book) (bool, error) { if _, ok := ctx.Deadline(); !ok { - t.Fatal("visitor lacks query deadline") + t.Fatal("visitor lacks the statement deadline") } visitCtx = ctx got = append(got, row) @@ -145,8 +162,11 @@ func TestGeneratedEachVisitsAndOwnsLifecycle(t *testing.T) { if !conn.rows.closed || conn.rows.closeCanceled { t.Fatal("rows were not drained before cancellation") } + if visitCtx != conn.rows.ctx { + t.Fatal("visitor did not receive the statement context") + } if visitCtx.Err() != context.Canceled { - t.Fatal("query context outlived Each") + t.Fatal("statement context outlived Each") } if conn.calls != 1 || !reflect.DeepEqual(conn.intents, []string{"eachgen.ListBooks"}) || !reflect.DeepEqual(conn.args, []any{int64(1)}) { t.Fatalf("calls=%d intents=%v args=%v", conn.calls, conn.intents, conn.args) @@ -198,6 +218,43 @@ func TestGeneratedEachStopAndErrors(t *testing.T) { } } +func TestGeneratedEachWithoutStatementContext(t *testing.T) { + conn := newEachConn() + conn.statementTimeout = 0 + ctx := context.WithValue(context.Background(), struct{}{}, "caller") + visits := 0 + err := eachgen.New(conn, nil).ListBooksEach(ctx, 0, func(vctx context.Context, row eachgen.Book) (bool, error) { + visits++ + if vctx.Value(struct{}{}) != "caller" { + t.Fatal("visitor lost the caller context") + } + if _, ok := vctx.Deadline(); ok { + t.Fatal("generated code must not start its own deadline") + } + return true, nil + }) + if err != nil || visits != 3 || !conn.rows.closed { + t.Fatalf("err=%v visits=%d closed=%v", err, visits, conn.rows.closed) + } +} + +func TestGeneratedEachStatementDeadline(t *testing.T) { + conn := newEachConn() + conn.statementTimeout = 10 * time.Millisecond + visits := 0 + err := eachgen.New(conn, nil).ListBooksEach(context.Background(), 0, func(ctx context.Context, row eachgen.Book) (bool, error) { + visits++ + <-ctx.Done() + return true, nil + }) + if !errors.Is(err, context.DeadlineExceeded) || visits != 1 { + t.Fatalf("err=%v visits=%d", err, visits) + } + if !conn.rows.closed || !conn.rows.closeCanceled { + t.Fatal("an expired statement must close under cancellation") + } +} + func TestGeneratedEachNilAndEmpty(t *testing.T) { conn := newEachConn() q := eachgen.New(conn, nil) diff --git a/internal/endtoend/testdata/wicked_compat/go/query.sql.go b/internal/endtoend/testdata/wicked_compat/go/query.sql.go index eacc4c8031..ff4e5dbd60 100644 --- a/internal/endtoend/testdata/wicked_compat/go/query.sql.go +++ b/internal/endtoend/testdata/wicked_compat/go/query.sql.go @@ -17,6 +17,7 @@ import ( "github.com/google/uuid" "github.com/jackc/pgx/v5" "github.com/rs/zerolog/log" + "github.com/stumble/wpgx" ) const createRecord = `-- name: CreateRecord :exec @@ -41,8 +42,7 @@ type CreateRecordRow struct { // -- timeout: 1s // -- invalidate: [GetRecord] func (q *Queries) CreateRecord(ctx context.Context, arg CreateRecordParams, getRecord *int64) error { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "compat.CreateRecord", time.Millisecond*1000) _, err := q.db.WExec(qctx, "compat.CreateRecord", createRecord, arg.ID, arg.ExternalID, @@ -94,8 +94,7 @@ func (q *ReadOnlyQueries) GetRecord(ctx context.Context, id int64) (*Record, err } func _GetRecord(ctx context.Context, q CacheQuerierConn, id int64) (*Record, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "compat.GetRecord", time.Millisecond*1000) q.GetConn().CountIntent("compat.GetRecord") dbRead := func() (any, time.Duration, error) { cacheDuration := time.Duration(time.Millisecond * 60000) diff --git a/internal/endtoend/testdata/wicked_compat/go/timeout_postgres_test.go b/internal/endtoend/testdata/wicked_compat/go/timeout_postgres_test.go new file mode 100644 index 0000000000..0765067b80 --- /dev/null +++ b/internal/endtoend/testdata/wicked_compat/go/timeout_postgres_test.go @@ -0,0 +1,166 @@ +package compat_test + +import ( + "context" + "errors" + "fmt" + "os" + "testing" + "time" + + "github.com/jackc/pgx/v5" + eachgen "github.com/sqlc-dev/sqlc/endtoend/wicked_each/go" + "github.com/stumble/wpgx" +) + +// Optional scoped integration check of the generated timeout (1s for every +// wicked_each query): it starts once the query has a connection. +func TestGeneratedTimeoutPostgres(t *testing.T) { + dsn := os.Getenv("SQLC_EACH_TEST_DSN") + if dsn == "" { + t.Skip("set SQLC_EACH_TEST_DSN to a disposable PostgreSQL database") + } + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + cfg, err := pgx.ParseConfig(dsn) + if err != nil { + t.Fatal(err) + } + setup, err := pgx.Connect(ctx, dsn) + if err != nil { + t.Fatal(err) + } + defer setup.Close(ctx) + schema := pgx.Identifier{fmt.Sprintf("sqlc_timeout_%d", time.Now().UnixNano())}.Sanitize() + if _, err := setup.Exec(ctx, "CREATE SCHEMA "+schema); err != nil { + t.Fatal(err) + } + defer func() { + cleanup, stop := context.WithTimeout(context.Background(), 10*time.Second) + defer stop() + if _, err := setup.Exec(cleanup, "DROP SCHEMA "+schema+" CASCADE"); err != nil { + t.Errorf("schema cleanup: %v", err) + } + }() + if _, err := setup.Exec(ctx, "CREATE TABLE "+schema+".books (id bigint PRIMARY KEY, value bytea NOT NULL)"); err != nil { + t.Fatal(err) + } + if _, err := setup.Exec(ctx, "INSERT INTO "+schema+".books VALUES (1, 'one'), (2, 'two')"); err != nil { + t.Fatal(err) + } + pool, err := wpgx.NewPool(ctx, &wpgx.Config{ + Username: cfg.User, Password: cfg.Password, Host: cfg.Host, Port: int(cfg.Port), DBName: cfg.Database, + MaxConns: 1, MinConns: 0, MaxConnLifetime: time.Minute, MaxConnIdleTime: time.Minute, + AppName: "sqlc_timeout_test", AcquireTimeout: 3 * time.Second, + BeforeAcquire: func(ctx context.Context, conn *pgx.Conn) bool { + _, err := conn.Exec(ctx, "SET search_path TO "+schema) + return err == nil + }, + }) + if err != nil { + t.Fatal(err) + } + defer pool.Close() + q := eachgen.New(pool.WConn(), nil) + + t.Run("waiting_for_a_connection_does_not_count", func(t *testing.T) { + held, err := pool.RawPrimaryPool().Acquire(ctx) + if err != nil { + t.Fatal(err) + } + time.AfterFunc(1300*time.Millisecond, held.Release) + start := time.Now() + books, err := q.ListBooks(ctx, 0) + if err != nil { + t.Fatalf("a 1.3s wait failed a 1s query: %v", err) + } + if len(books) != 2 || time.Since(start) < 1200*time.Millisecond { + t.Fatalf("books=%d elapsed=%s", len(books), time.Since(start)) + } + }) + + t.Run("visitor_gets_the_statement_deadline", func(t *testing.T) { + start := time.Now() + err := q.ListBooksEach(ctx, 0, func(vctx context.Context, _ eachgen.Book) (bool, error) { + deadline, ok := vctx.Deadline() + if !ok || deadline.Before(start.Add(900*time.Millisecond)) || deadline.After(time.Now().Add(time.Second)) { + return false, fmt.Errorf("deadline=%v ok=%v", deadline, ok) + } + return true, nil + }) + if err != nil { + t.Fatal(err) + } + }) + + t.Run("a_visitor_returning_the_deadline_reports_the_database_timeout", func(t *testing.T) { + err := q.ListBooksEach(ctx, 0, func(vctx context.Context, _ eachgen.Book) (bool, error) { + <-vctx.Done() + return false, vctx.Err() + }) + if !errors.Is(err, wpgx.ErrDBTimeout) || !errors.Is(err, context.DeadlineExceeded) { + t.Fatalf("err=%v", err) + } + }) + + t.Run("draining_past_the_timeout_after_an_early_stop_fails", func(t *testing.T) { + slow := eachgen.New(&slowCloseConn{WGConn: pool.WConn()}, nil) + err := slow.ListBooksEach(ctx, 0, func(context.Context, eachgen.Book) (bool, error) { + return false, nil + }) + if !errors.Is(err, wpgx.ErrDBTimeout) { + t.Fatalf("err=%v", err) + } + }) + + t.Run("a_blocked_query_reports_the_database_timeout", func(t *testing.T) { + locker, err := pgx.Connect(ctx, dsn) + if err != nil { + t.Fatal(err) + } + defer locker.Close(ctx) + tx, err := locker.Begin(ctx) + if err != nil { + t.Fatal(err) + } + defer func() { _ = tx.Rollback(ctx) }() + if _, err := tx.Exec(ctx, "LOCK TABLE "+schema+".books IN ACCESS EXCLUSIVE MODE"); err != nil { + t.Fatal(err) + } + start := time.Now() + _, err = q.ListBooks(ctx, 0) + if !errors.Is(err, wpgx.ErrDBTimeout) || !errors.Is(err, context.DeadlineExceeded) { + t.Fatalf("ListBooks err=%v", err) + } + err = q.ListBooksEach(ctx, 0, func(context.Context, eachgen.Book) (bool, error) { return true, nil }) + if !errors.Is(err, wpgx.ErrDBTimeout) { + t.Fatalf("ListBooksEach err=%v", err) + } + if elapsed := time.Since(start); elapsed > 4*time.Second { + t.Fatalf("two 1s timeouts took %s", elapsed) + } + }) +} + +// slowCloseConn returns rows whose Close waits until the statement context +// ends, as a slow drain of buffered rows would. +type slowCloseConn struct{ wpgx.WGConn } + +func (c *slowCloseConn) WQuery(ctx context.Context, name, sql string, args ...any) (pgx.Rows, error) { + rows, err := c.WGConn.WQuery(ctx, name, sql, args...) + if err != nil { + return rows, err + } + return slowCloseRows{rows}, nil +} + +type slowCloseRows struct{ pgx.Rows } + +func (r slowCloseRows) Context() context.Context { + return r.Rows.(interface{ Context() context.Context }).Context() +} + +func (r slowCloseRows) Close() { + <-r.Context().Done() + r.Rows.Close() +} diff --git a/internal/endtoend/testdata/wicked_each/go/querier.go b/internal/endtoend/testdata/wicked_each/go/querier.go index 349799984c..0d8561186b 100644 --- a/internal/endtoend/testdata/wicked_each/go/querier.go +++ b/internal/endtoend/testdata/wicked_each/go/querier.go @@ -13,6 +13,10 @@ type Querier interface { ListCachedBooks(ctx context.Context) ([]Book, error) + ListFromVctx(ctx context.Context, vctx int64) ([]Book, error) + + ListFromWpgx(ctx context.Context, wpgx_ int64) ([]Book, error) + ListIDs(ctx context.Context) ([]int64, error) ListNamedScalar(ctx context.Context) ([]int64, error) @@ -30,6 +34,10 @@ type EachQuerier interface { ListCachedBooksEach(ctx context.Context, visit func(context.Context, Book) (more bool, err error)) error + ListFromVctxEach(ctx context.Context, vctx int64, visit func(context.Context, Book) (more bool, err error)) error + + ListFromWpgxEach(ctx context.Context, wpgx_ int64, visit func(context.Context, Book) (more bool, err error)) error + ListIDsEach(ctx context.Context, visit func(context.Context, int64) (more bool, err error)) error ListNamedScalarEach(ctx context.Context, visit func(context.Context, int64) (more bool, err error)) error diff --git a/internal/endtoend/testdata/wicked_each/go/query.sql.go b/internal/endtoend/testdata/wicked_each/go/query.sql.go index 47ec342a91..ca2a180654 100644 --- a/internal/endtoend/testdata/wicked_each/go/query.sql.go +++ b/internal/endtoend/testdata/wicked_each/go/query.sql.go @@ -15,6 +15,7 @@ import ( "time" "github.com/rs/zerolog/log" + "github.com/stumble/wpgx" ) const listBooks = `-- name: ListBooks :many @@ -32,8 +33,7 @@ func (q *ReadOnlyQueries) ListBooks(ctx context.Context, visit int64) ([]Book, e } func _ListBooks(ctx context.Context, q CacheQuerierConn, visit int64) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListBooks", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListBooks") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListBooks", listBooks, visit) if err != nil { @@ -59,7 +59,8 @@ func _ListBooks(ctx context.Context, q CacheQuerierConn, visit int64) ([]Book, e // It directly queries the DB, bypassing the slice method's result cache. // Return true to continue or false to stop the whole read; to skip a row, // omit its output and return true. Errors are returned after rows are closed. -// The query timeout covers the synchronous visitor and draining. The visitor +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor // must respect ctx and must not query again on the same active connection. // Normal stop and visitor error drain by default; cancel a query-specific // caller context to abort transfer, which may invalidate its connection/tx. @@ -76,16 +77,19 @@ func _ListBooksEach(ctx context.Context, q CacheQuerierConn, visit int64, visit1 if visit1 == nil { return fmt.Errorf("ListBooksEach: nil visitor") } - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListBooks", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListBooks") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListBooks", listBooks, visit) if err != nil { return err } defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } for rows.Next() { - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } var eachRow *Book = new(Book) @@ -94,9 +98,9 @@ func _ListBooksEach(ctx context.Context, q CacheQuerierConn, visit int64, visit1 } more, err := visit1(qctx, *eachRow) if err != nil { - return err + return wpgx.StatementErr(qctx, err) } - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } if !more { @@ -104,12 +108,14 @@ func _ListBooksEach(ctx context.Context, q CacheQuerierConn, visit int64, visit1 } } // Close may drain pending results and surface a server error after a - // successful early stop. It must run before checking Err and cancelling. + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. rows.Close() - if err := rows.Err(); err != nil { + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { return err } - return qctx.Err() + return ctx.Err() } const listCachedBooks = `-- name: ListCachedBooks :many @@ -128,8 +134,7 @@ func (q *ReadOnlyQueries) ListCachedBooks(ctx context.Context) ([]Book, error) { } func _ListCachedBooks(ctx context.Context, q CacheQuerierConn) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListCachedBooks", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListCachedBooks") dbRead := func() (any, time.Duration, error) { cacheDuration := time.Duration(time.Millisecond * 5000) @@ -168,7 +173,8 @@ func _ListCachedBooks(ctx context.Context, q CacheQuerierConn) ([]Book, error) { // It directly queries the DB, bypassing the slice method's result cache. // Return true to continue or false to stop the whole read; to skip a row, // omit its output and return true. Errors are returned after rows are closed. -// The query timeout covers the synchronous visitor and draining. The visitor +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor // must respect ctx and must not query again on the same active connection. // Normal stop and visitor error drain by default; cancel a query-specific // caller context to abort transfer, which may invalidate its connection/tx. @@ -185,16 +191,19 @@ func _ListCachedBooksEach(ctx context.Context, q CacheQuerierConn, visit func(co if visit == nil { return fmt.Errorf("ListCachedBooksEach: nil visitor") } - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListCachedBooks", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListCachedBooks") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListCachedBooks", listCachedBooks) if err != nil { return err } defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } for rows.Next() { - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } var eachRow *Book = new(Book) @@ -203,9 +212,109 @@ func _ListCachedBooksEach(ctx context.Context, q CacheQuerierConn, visit func(co } more, err := visit(qctx, *eachRow) if err != nil { + return wpgx.StatementErr(qctx, err) + } + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { + return err + } + if !more { + break + } + } + // Close may drain pending results and surface a server error after a + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. + rows.Close() + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { + return err + } + return ctx.Err() +} + +const listFromVctx = `-- name: ListFromVctx :many +SELECT id, value FROM books WHERE id >= $1 ORDER BY id +` + +// -- timeout: 1s +// -- each: true +func (q *Queries) ListFromVctx(ctx context.Context, vctx int64) ([]Book, error) { + return _ListFromVctx(ctx, q.AsReadOnly(), vctx) +} + +func (q *ReadOnlyQueries) ListFromVctx(ctx context.Context, vctx int64) ([]Book, error) { + return _ListFromVctx(ctx, q, vctx) +} + +func _ListFromVctx(ctx context.Context, q CacheQuerierConn, vctx int64) ([]Book, error) { + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListFromVctx", time.Millisecond*1000) + q.GetConn().CountIntent("eachgen.ListFromVctx") + rows, err := q.GetConn().WQuery(qctx, "eachgen.ListFromVctx", listFromVctx, vctx) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Book + for rows.Next() { + var i *Book = new(Book) + if err := rows.Scan(&i.ID, &i.Value); err != nil { + return nil, err + } + items = append(items, *i) + } + if err := rows.Err(); err != nil { + return nil, err + } + + return items, err +} + +// ListFromVctxEach visits rows in query order without collecting a result slice. +// It directly queries the DB, bypassing the slice method's result cache. +// Return true to continue or false to stop the whole read; to skip a row, +// omit its output and return true. Errors are returned after rows are closed. +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor +// must respect ctx and must not query again on the same active connection. +// Normal stop and visitor error drain by default; cancel a query-specific +// caller context to abort transfer, which may invalidate its connection/tx. +func (q *Queries) ListFromVctxEach(ctx context.Context, vctx int64, visit func(context.Context, Book) (more bool, err error)) error { + return _ListFromVctxEach(ctx, q.AsReadOnly(), vctx, visit) +} + +// ListFromVctxEach has the same consumption and lifetime contract as Queries.ListFromVctxEach. +func (q *ReadOnlyQueries) ListFromVctxEach(ctx context.Context, vctx int64, visit func(context.Context, Book) (more bool, err error)) error { + return _ListFromVctxEach(ctx, q, vctx, visit) +} + +func _ListFromVctxEach(ctx context.Context, q CacheQuerierConn, vctx int64, visit func(context.Context, Book) (more bool, err error)) error { + if visit == nil { + return fmt.Errorf("ListFromVctxEach: nil visitor") + } + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListFromVctx", time.Millisecond*1000) + q.GetConn().CountIntent("eachgen.ListFromVctx") + rows, err := q.GetConn().WQuery(qctx, "eachgen.ListFromVctx", listFromVctx, vctx) + if err != nil { + return err + } + defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } + for rows.Next() { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { + return err + } + var eachRow *Book = new(Book) + if err := rows.Scan(&eachRow.ID, &eachRow.Value); err != nil { return err } - if err := qctx.Err(); err != nil { + more, err := visit(qctx, *eachRow) + if err != nil { + return wpgx.StatementErr(qctx, err) + } + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } if !more { @@ -213,12 +322,114 @@ func _ListCachedBooksEach(ctx context.Context, q CacheQuerierConn, visit func(co } } // Close may drain pending results and surface a server error after a - // successful early stop. It must run before checking Err and cancelling. + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. rows.Close() + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { + return err + } + return ctx.Err() +} + +const listFromWpgx = `-- name: ListFromWpgx :many +SELECT id, value FROM books WHERE id >= $1 ORDER BY id +` + +// -- timeout: 1s +// -- each: true +func (q *Queries) ListFromWpgx(ctx context.Context, wpgx_ int64) ([]Book, error) { + return _ListFromWpgx(ctx, q.AsReadOnly(), wpgx_) +} + +func (q *ReadOnlyQueries) ListFromWpgx(ctx context.Context, wpgx_ int64) ([]Book, error) { + return _ListFromWpgx(ctx, q, wpgx_) +} + +func _ListFromWpgx(ctx context.Context, q CacheQuerierConn, wpgx_ int64) ([]Book, error) { + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListFromWpgx", time.Millisecond*1000) + q.GetConn().CountIntent("eachgen.ListFromWpgx") + rows, err := q.GetConn().WQuery(qctx, "eachgen.ListFromWpgx", listFromWpgx, wpgx_) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Book + for rows.Next() { + var i *Book = new(Book) + if err := rows.Scan(&i.ID, &i.Value); err != nil { + return nil, err + } + items = append(items, *i) + } if err := rows.Err(); err != nil { + return nil, err + } + + return items, err +} + +// ListFromWpgxEach visits rows in query order without collecting a result slice. +// It directly queries the DB, bypassing the slice method's result cache. +// Return true to continue or false to stop the whole read; to skip a row, +// omit its output and return true. Errors are returned after rows are closed. +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor +// must respect ctx and must not query again on the same active connection. +// Normal stop and visitor error drain by default; cancel a query-specific +// caller context to abort transfer, which may invalidate its connection/tx. +func (q *Queries) ListFromWpgxEach(ctx context.Context, wpgx_ int64, visit func(context.Context, Book) (more bool, err error)) error { + return _ListFromWpgxEach(ctx, q.AsReadOnly(), wpgx_, visit) +} + +// ListFromWpgxEach has the same consumption and lifetime contract as Queries.ListFromWpgxEach. +func (q *ReadOnlyQueries) ListFromWpgxEach(ctx context.Context, wpgx_ int64, visit func(context.Context, Book) (more bool, err error)) error { + return _ListFromWpgxEach(ctx, q, wpgx_, visit) +} + +func _ListFromWpgxEach(ctx context.Context, q CacheQuerierConn, wpgx_ int64, visit func(context.Context, Book) (more bool, err error)) error { + if visit == nil { + return fmt.Errorf("ListFromWpgxEach: nil visitor") + } + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListFromWpgx", time.Millisecond*1000) + q.GetConn().CountIntent("eachgen.ListFromWpgx") + rows, err := q.GetConn().WQuery(qctx, "eachgen.ListFromWpgx", listFromWpgx, wpgx_) + if err != nil { return err } - return qctx.Err() + defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } + for rows.Next() { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { + return err + } + var eachRow *Book = new(Book) + if err := rows.Scan(&eachRow.ID, &eachRow.Value); err != nil { + return err + } + more, err := visit(qctx, *eachRow) + if err != nil { + return wpgx.StatementErr(qctx, err) + } + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { + return err + } + if !more { + break + } + } + // Close may drain pending results and surface a server error after a + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. + rows.Close() + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { + return err + } + return ctx.Err() } const listIDs = `-- name: ListIDs :many @@ -236,8 +447,7 @@ func (q *ReadOnlyQueries) ListIDs(ctx context.Context) ([]int64, error) { } func _ListIDs(ctx context.Context, q CacheQuerierConn) ([]int64, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListIDs", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListIDs") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListIDs", listIDs) if err != nil { @@ -263,7 +473,8 @@ func _ListIDs(ctx context.Context, q CacheQuerierConn) ([]int64, error) { // It directly queries the DB, bypassing the slice method's result cache. // Return true to continue or false to stop the whole read; to skip a row, // omit its output and return true. Errors are returned after rows are closed. -// The query timeout covers the synchronous visitor and draining. The visitor +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor // must respect ctx and must not query again on the same active connection. // Normal stop and visitor error drain by default; cancel a query-specific // caller context to abort transfer, which may invalidate its connection/tx. @@ -280,16 +491,19 @@ func _ListIDsEach(ctx context.Context, q CacheQuerierConn, visit func(context.Co if visit == nil { return fmt.Errorf("ListIDsEach: nil visitor") } - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListIDs", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListIDs") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListIDs", listIDs) if err != nil { return err } defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } for rows.Next() { - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } var eachRow *int64 = new(int64) @@ -298,9 +512,9 @@ func _ListIDsEach(ctx context.Context, q CacheQuerierConn, visit func(context.Co } more, err := visit(qctx, *eachRow) if err != nil { - return err + return wpgx.StatementErr(qctx, err) } - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } if !more { @@ -308,12 +522,14 @@ func _ListIDsEach(ctx context.Context, q CacheQuerierConn, visit func(context.Co } } // Close may drain pending results and surface a server error after a - // successful early stop. It must run before checking Err and cancelling. + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. rows.Close() - if err := rows.Err(); err != nil { + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { return err } - return qctx.Err() + return ctx.Err() } const listNamedScalar = `-- name: ListNamedScalar :many @@ -331,8 +547,7 @@ func (q *ReadOnlyQueries) ListNamedScalar(ctx context.Context) ([]int64, error) } func _ListNamedScalar(ctx context.Context, q CacheQuerierConn) ([]int64, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListNamedScalar", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListNamedScalar") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListNamedScalar", listNamedScalar) if err != nil { @@ -358,7 +573,8 @@ func _ListNamedScalar(ctx context.Context, q CacheQuerierConn) ([]int64, error) // It directly queries the DB, bypassing the slice method's result cache. // Return true to continue or false to stop the whole read; to skip a row, // omit its output and return true. Errors are returned after rows are closed. -// The query timeout covers the synchronous visitor and draining. The visitor +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor // must respect ctx and must not query again on the same active connection. // Normal stop and visitor error drain by default; cancel a query-specific // caller context to abort transfer, which may invalidate its connection/tx. @@ -375,16 +591,19 @@ func _ListNamedScalarEach(ctx context.Context, q CacheQuerierConn, visit func(co if visit == nil { return fmt.Errorf("ListNamedScalarEach: nil visitor") } - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListNamedScalar", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListNamedScalar") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListNamedScalar", listNamedScalar) if err != nil { return err } defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } for rows.Next() { - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } var eachRow *int64 = new(int64) @@ -393,9 +612,9 @@ func _ListNamedScalarEach(ctx context.Context, q CacheQuerierConn, visit func(co } more, err := visit(qctx, *eachRow) if err != nil { - return err + return wpgx.StatementErr(qctx, err) } - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } if !more { @@ -403,12 +622,14 @@ func _ListNamedScalarEach(ctx context.Context, q CacheQuerierConn, visit func(co } } // Close may drain pending results and surface a server error after a - // successful early stop. It must run before checking Err and cancelling. + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. rows.Close() - if err := rows.Err(); err != nil { + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { return err } - return qctx.Err() + return ctx.Err() } const listPrimaryBooks = `-- name: ListPrimaryBooks :many @@ -424,8 +645,7 @@ func (q *Queries) ListPrimaryBooks(ctx context.Context) ([]Book, error) { } func _ListPrimaryBooks(ctx context.Context, q CacheQuerierConn) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListPrimaryBooks", time.Millisecond*1000) rows, err := q.GetConn().WQuery(qctx, "eachgen.ListPrimaryBooks", listPrimaryBooks) if err != nil { return nil, err @@ -450,7 +670,8 @@ func _ListPrimaryBooks(ctx context.Context, q CacheQuerierConn) ([]Book, error) // It directly queries the DB, bypassing the slice method's result cache. // Return true to continue or false to stop the whole read; to skip a row, // omit its output and return true. Errors are returned after rows are closed. -// The query timeout covers the synchronous visitor and draining. The visitor +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor // must respect ctx and must not query again on the same active connection. // Normal stop and visitor error drain by default; cancel a query-specific // caller context to abort transfer, which may invalidate its connection/tx. @@ -462,16 +683,19 @@ func _ListPrimaryBooksEach(ctx context.Context, q CacheQuerierConn, visit func(c if visit == nil { return fmt.Errorf("ListPrimaryBooksEach: nil visitor") } - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListPrimaryBooks", time.Millisecond*1000) rows, err := q.GetConn().WQuery(qctx, "eachgen.ListPrimaryBooks", listPrimaryBooks) if err != nil { return err } defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } for rows.Next() { - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } var eachRow *Book = new(Book) @@ -480,9 +704,9 @@ func _ListPrimaryBooksEach(ctx context.Context, q CacheQuerierConn, visit func(c } more, err := visit(qctx, *eachRow) if err != nil { - return err + return wpgx.StatementErr(qctx, err) } - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } if !more { @@ -490,12 +714,14 @@ func _ListPrimaryBooksEach(ctx context.Context, q CacheQuerierConn, visit func(c } } // Close may drain pending results and surface a server error after a - // successful early stop. It must run before checking Err and cancelling. + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. rows.Close() - if err := rows.Err(); err != nil { + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { return err } - return qctx.Err() + return ctx.Err() } const listRange = `-- name: ListRange :many @@ -518,8 +744,7 @@ func (q *ReadOnlyQueries) ListRange(ctx context.Context, arg ListRangeParams) ([ } func _ListRange(ctx context.Context, q CacheQuerierConn, arg ListRangeParams) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListRange", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListRange") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListRange", listRange, arg.FromID, arg.ToID) if err != nil { @@ -545,7 +770,8 @@ func _ListRange(ctx context.Context, q CacheQuerierConn, arg ListRangeParams) ([ // It directly queries the DB, bypassing the slice method's result cache. // Return true to continue or false to stop the whole read; to skip a row, // omit its output and return true. Errors are returned after rows are closed. -// The query timeout covers the synchronous visitor and draining. The visitor +// The query's database timeout starts once it has a connection and covers the +// synchronous visitor and draining; the visitor's ctx carries it. The visitor // must respect ctx and must not query again on the same active connection. // Normal stop and visitor error drain by default; cancel a query-specific // caller context to abort transfer, which may invalidate its connection/tx. @@ -562,16 +788,19 @@ func _ListRangeEach(ctx context.Context, q CacheQuerierConn, arg ListRangeParams if visit == nil { return fmt.Errorf("ListRangeEach: nil visitor") } - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "eachgen.ListRange", time.Millisecond*1000) q.GetConn().CountIntent("eachgen.ListRange") rows, err := q.GetConn().WQuery(qctx, "eachgen.ListRange", listRange, arg.FromID, arg.ToID) if err != nil { return err } defer rows.Close() + // wpgx rows carry the statement context and its database timeout. + if sc, ok := rows.(interface{ Context() context.Context }); ok { + qctx = sc.Context() + } for rows.Next() { - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } var eachRow *Book = new(Book) @@ -580,9 +809,9 @@ func _ListRangeEach(ctx context.Context, q CacheQuerierConn, arg ListRangeParams } more, err := visit(qctx, *eachRow) if err != nil { - return err + return wpgx.StatementErr(qctx, err) } - if err := qctx.Err(); err != nil { + if err := wpgx.StatementErr(qctx, qctx.Err()); err != nil { return err } if !more { @@ -590,12 +819,14 @@ func _ListRangeEach(ctx context.Context, q CacheQuerierConn, arg ListRangeParams } } // Close may drain pending results and surface a server error after a - // successful early stop. It must run before checking Err and cancelling. + // successful early stop. It must run before checking Err. StatementErr + // also reports a database timeout that expired while reading or draining + // buffered rows, but not the cancellation that closing causes. rows.Close() - if err := rows.Err(); err != nil { + if err := wpgx.StatementErr(qctx, rows.Err()); err != nil { return err } - return qctx.Err() + return ctx.Err() } //// auto generated functions diff --git a/internal/endtoend/testdata/wicked_each/query.sql b/internal/endtoend/testdata/wicked_each/query.sql index fcc67eddf9..ea727575c0 100644 --- a/internal/endtoend/testdata/wicked_each/query.sql +++ b/internal/endtoend/testdata/wicked_each/query.sql @@ -30,3 +30,13 @@ SELECT id, value FROM books ORDER BY id; -- -- timeout: 1s -- -- each: true SELECT id, value FROM books WHERE id BETWEEN @from_id AND @to_id ORDER BY id; + +-- name: ListFromWpgx :many +-- -- timeout: 1s +-- -- each: true +SELECT id, value FROM books WHERE id >= @wpgx ORDER BY id; + +-- name: ListFromVctx :many +-- -- timeout: 1s +-- -- each: true +SELECT id, value FROM books WHERE id >= @vctx ORDER BY id; diff --git a/internal/endtoend/testdata/wicked_many/go/query.sql.go b/internal/endtoend/testdata/wicked_many/go/query.sql.go index 1e42118616..ed8dcb8ef3 100644 --- a/internal/endtoend/testdata/wicked_many/go/query.sql.go +++ b/internal/endtoend/testdata/wicked_many/go/query.sql.go @@ -15,6 +15,7 @@ import ( "time" "github.com/rs/zerolog/log" + "github.com/stumble/wpgx" ) const deleteAndList = `-- name: DeleteAndList :many @@ -37,8 +38,7 @@ func (q *ReadOnlyQueries) DeleteAndList(ctx context.Context, beforeID int64) ([] } func _DeleteAndList(ctx context.Context, q CacheQuerierConn, beforeID int64) ([]DeleteAndListRow, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "manycompat.DeleteAndList", time.Millisecond*1000) q.GetConn().CountIntent("manycompat.DeleteAndList") rows, err := q.GetConn().WQuery(qctx, "manycompat.DeleteAndList", deleteAndList, beforeID) if err != nil { @@ -74,8 +74,7 @@ func (q *ReadOnlyQueries) ListBooks(ctx context.Context, minID int64) ([]Book, e } func _ListBooks(ctx context.Context, q CacheQuerierConn, minID int64) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "manycompat.ListBooks", time.Millisecond*1000) q.GetConn().CountIntent("manycompat.ListBooks") rows, err := q.GetConn().WQuery(qctx, "manycompat.ListBooks", listBooks, minID) if err != nil { @@ -112,8 +111,7 @@ func (q *ReadOnlyQueries) ListCachedBooks(ctx context.Context) ([]Book, error) { } func _ListCachedBooks(ctx context.Context, q CacheQuerierConn) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "manycompat.ListCachedBooks", time.Millisecond*1000) q.GetConn().CountIntent("manycompat.ListCachedBooks") dbRead := func() (any, time.Duration, error) { cacheDuration := time.Duration(time.Millisecond * 5000) @@ -174,8 +172,7 @@ func (q *ReadOnlyQueries) ListCachedRange(ctx context.Context, arg ListCachedRan } func _ListCachedRange(ctx context.Context, q CacheQuerierConn, arg ListCachedRangeParams) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "manycompat.ListCachedRange", time.Millisecond*1000) q.GetConn().CountIntent("manycompat.ListCachedRange") dbRead := func() (any, time.Duration, error) { cacheDuration := time.Duration(time.Millisecond * 5000) @@ -224,8 +221,7 @@ func (q *ReadOnlyQueries) ListIDs(ctx context.Context) ([]int64, error) { } func _ListIDs(ctx context.Context, q CacheQuerierConn) ([]int64, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "manycompat.ListIDs", time.Millisecond*1000) q.GetConn().CountIntent("manycompat.ListIDs") rows, err := q.GetConn().WQuery(qctx, "manycompat.ListIDs", listIDs) if err != nil { @@ -259,8 +255,7 @@ func (q *Queries) ListPrimaryBooks(ctx context.Context) ([]Book, error) { } func _ListPrimaryBooks(ctx context.Context, q CacheQuerierConn) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "manycompat.ListPrimaryBooks", time.Millisecond*1000) rows, err := q.GetConn().WQuery(qctx, "manycompat.ListPrimaryBooks", listPrimaryBooks) if err != nil { return nil, err @@ -299,8 +294,7 @@ func (q *Queries) PutBooks(ctx context.Context, arg PutBooksParams) ([]Book, err } func _PutBooks(ctx context.Context, q CacheWGConn, arg PutBooksParams) ([]Book, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "manycompat.PutBooks", time.Millisecond*1000) rows, err := q.GetConn().WQuery(qctx, "manycompat.PutBooks", putBooks, arg.ID, arg.Value) if err != nil { return nil, err diff --git a/internal/endtoend/testdata/wicked_primary/go/query.sql.go b/internal/endtoend/testdata/wicked_primary/go/query.sql.go index ac15b5da20..30cd87db24 100644 --- a/internal/endtoend/testdata/wicked_primary/go/query.sql.go +++ b/internal/endtoend/testdata/wicked_primary/go/query.sql.go @@ -16,6 +16,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/rs/zerolog/log" + "github.com/stumble/wpgx" ) const getRevenue = `-- name: GetRevenue :one @@ -33,8 +34,7 @@ func (q *ReadOnlyQueries) GetRevenue(ctx context.Context, id int64) (*BookRevenu } func _GetRevenue(ctx context.Context, q CacheQuerierConn, id int64) (*BookRevenue, error) { - qctx, cancel := context.WithTimeout(ctx, time.Millisecond*250) - defer cancel() + qctx := wpgx.WithDBTimeout(ctx, "revenues.GetRevenue", time.Millisecond*250) q.GetConn().CountIntent("revenues.GetRevenue") dbRead := func() (any, time.Duration, error) { cacheDuration := time.Duration(time.Millisecond * 60000)