pgfake

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package pgfake provides the pgx shapes sqlb's own tests run against, so the engine's suite stays database-free.

It exists because ADR-0040 made pgx the contract: an executor is now pgx-shaped, and a canned result set has to be a pgx.Rows rather than a database/sql driver anyone can register. Two of those interfaces are wide — Rows has nine methods and Tx eleven — and writing them out in three test packages would be three chances to drift. So the boilerplate lives here and each package keeps its own policy: what a statement answers, and what gets recorded.

This is a test double and nothing here should reach a real database. The methods sqlb does not use panic rather than returning a zero value, because a test that silently reads nothing from CopyFrom is worse than one that stops.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rows

type Rows struct {
	Cols []string
	Data [][]any
	// Fail is reported by Err, standing in for a statement that failed while
	// its result was being read rather than when it was sent. pgx does this on
	// the extended protocol, which is why every scanner here reads Err.
	Fail error
	// contains filtered or unexported fields
}

Rows is a canned result set: column names, row values, and optionally a failure that Err reports once iteration ends.

func (*Rows) Close

func (r *Rows) Close()

func (*Rows) Closed

func (r *Rows) Closed() bool

Closed reports whether Close has been called, which is how a test asserts the result set was released.

func (*Rows) CommandTag

func (r *Rows) CommandTag() pgconn.CommandTag

func (*Rows) Conn

func (r *Rows) Conn() *pgx.Conn

func (*Rows) Err

func (r *Rows) Err() error

func (*Rows) FieldDescriptions

func (r *Rows) FieldDescriptions() []pgconn.FieldDescription

func (*Rows) Next

func (r *Rows) Next() bool

func (*Rows) RawValues

func (r *Rows) RawValues() [][]byte

RawValues has no answer here: the values were never on a wire, so there are no unparsed bytes to hand back and inventing some would be a lie a test could come to depend on.

func (*Rows) Scan

func (r *Rows) Scan(dest ...any) error

Scan follows pgx's convention closely enough for the scanners to be exercised honestly: a destination implementing sql.Scanner is offered the raw value, which is pgx's own last-resort plan and the path every pgtype takes, and everything else is assigned by reflection.

func (*Rows) Values

func (r *Rows) Values() ([]any, error)

type Statements

type Statements interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}

Statements is what a Tx runs its statements through — whatever the test package uses as its executor. Named for what it accepts rather than for the connection it stands in for, because pgx.Tx already spends the name Conn on a method.

type Tx

type Tx struct {
	Statements
	OnCommit   func() error
	OnRollback func() error
	// contains filtered or unexported fields
}

Tx adapts a Statements onto pgx.Tx. Statements go through unchanged; the boundary is reported through OnCommit and OnRollback, which is what lets a test assert that a unit of work was wrapped and how it ended.

Commit and Rollback are each answered once. A second call returns pgx.ErrTxClosed, as a real transaction does — WithTx relies on that error to tell an already-finished transaction from a failed rollback.

func (*Tx) Begin

func (t *Tx) Begin(context.Context) (pgx.Tx, error)

Begin would be a savepoint. sqlb's nesting joins the outer transaction rather than nesting (ADR-0020), so nothing should reach this.

func (*Tx) Commit

func (t *Tx) Commit(context.Context) error

func (*Tx) Conn

func (t *Tx) Conn() *pgx.Conn

func (*Tx) CopyFrom

func (*Tx) LargeObjects

func (t *Tx) LargeObjects() pgx.LargeObjects

func (*Tx) Prepare

func (*Tx) QueryRow

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

func (*Tx) Rollback

func (t *Tx) Rollback(context.Context) error

func (*Tx) SendBatch

func (t *Tx) SendBatch(context.Context, *pgx.Batch) pgx.BatchResults

Jump to

Keyboard shortcuts

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