Files
beacon-server/db/statement_capture_test.go
T
MrAlders0n 433ad0234a Observer comparison: read each observer's receptions on their own (#260)
* Read each observer's receptions on their own in the observer comparison

* Tighten the observer comparison plan checks
2026-10-20 18:47:08 -04:00

34 lines
805 B
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package db
import (
"context"
"strings"
"github.com/jackc/pgx/v5"
)
// statementCapture records the SQL and args of sqlc statements whose name starts with name, for EXPLAIN.
type statementCapture struct {
pgx.Tx
name string
statement string
args []any
}
func (c *statementCapture) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error) {
if strings.Contains(sql, "-- name: "+c.name) {
c.statement, c.args = sql, args
}
return c.Tx.Query(ctx, sql, args...)
}
func (c *statementCapture) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row {
if strings.Contains(sql, "-- name: "+c.name) {
c.statement, c.args = sql, args
}
return c.Tx.QueryRow(ctx, sql, args...)
}