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 ¶
- type Rows
- func (r *Rows) Close()
- func (r *Rows) Closed() bool
- func (r *Rows) CommandTag() pgconn.CommandTag
- func (r *Rows) Conn() *pgx.Conn
- func (r *Rows) Err() error
- func (r *Rows) FieldDescriptions() []pgconn.FieldDescription
- func (r *Rows) Next() bool
- func (r *Rows) RawValues() [][]byte
- func (r *Rows) Scan(dest ...any) error
- func (r *Rows) Values() ([]any, error)
- type Statements
- type Tx
- func (t *Tx) Begin(context.Context) (pgx.Tx, error)
- func (t *Tx) Commit(context.Context) error
- func (t *Tx) Conn() *pgx.Conn
- func (t *Tx) CopyFrom(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) (int64, error)
- func (t *Tx) LargeObjects() pgx.LargeObjects
- func (t *Tx) Prepare(context.Context, string, string) (*pgconn.StatementDescription, error)
- func (t *Tx) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- func (t *Tx) Rollback(context.Context) error
- func (t *Tx) SendBatch(context.Context, *pgx.Batch) pgx.BatchResults
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) Closed ¶
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) FieldDescriptions ¶
func (r *Rows) FieldDescriptions() []pgconn.FieldDescription
func (*Rows) RawValues ¶
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.
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 ¶
Begin would be a savepoint. sqlb's nesting joins the outer transaction rather than nesting (ADR-0020), so nothing should reach this.
func (*Tx) CopyFrom ¶
func (t *Tx) CopyFrom(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) (int64, error)
func (*Tx) LargeObjects ¶
func (t *Tx) LargeObjects() pgx.LargeObjects