dbtest

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package dbtest provides test helpers for database stores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QueryCounter

type QueryCounter struct {
	// contains filtered or unexported fields
}

QueryCounter wraps a store.DBTX and counts every query-level call (Exec, Query, QueryRow). Begin is counted once (for the BEGIN itself); calls on the returned transaction are also counted via a wrapped Tx.

func NewQueryCounter

func NewQueryCounter(db store.DBTX) *QueryCounter

NewQueryCounter wraps the given DBTX with call counting.

func (*QueryCounter) Begin

func (qc *QueryCounter) Begin(ctx context.Context) (pgx.Tx, error)

Begin delegates to the underlying DBTX and returns a counted transaction.

func (*QueryCounter) Count

func (qc *QueryCounter) Count() int

Count returns the number of database calls observed so far.

func (*QueryCounter) Exec

func (qc *QueryCounter) Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)

Exec delegates to the underlying DBTX and increments the counter.

func (*QueryCounter) Query

func (qc *QueryCounter) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

Query delegates to the underlying DBTX and increments the counter.

func (*QueryCounter) QueryRow

func (qc *QueryCounter) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

QueryRow delegates to the underlying DBTX and increments the counter.

func (*QueryCounter) Reset

func (qc *QueryCounter) Reset()

Reset sets the counter back to zero.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL