dbtest

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLifecycle

func WithLifecycle(createFunc, cleanFunc func(context.Context, *sql.DB, *sql.DB) (sql.Result, error)) func(*DB)

func WithPublication

func WithPublication(name string) func(*DB)

func WithPublicationClean

func WithPublicationClean(name string) func(*DB)

func WithReplicationSlotClean

func WithReplicationSlotClean(prefix string) func(*DB)

func WithSchema

func WithSchema(name string) func(*DB)

func WithTable

func WithTable(namespace string, name string, fieldDefinitions ...string) func(*DB)

func WithTruncate

func WithTruncate(namespace, name string) func(*DB)

Types

type DB

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

DB is used to help test interactions with Postgres. Unlike a conventional application, we create global state that lives outside of a schema, and require creation of tables with arbitrary schemas. We also reach deeper into the connection pools than most, requiring us to explicitly close any connections we create.

This test helper can be used to ensure connections are closed, and test structure clean-up happens reliably.

func Configure

func Configure(opts ...func(*DB)) *DB

func (*DB) GetConnection

func (d *DB) GetConnection(ctx context.Context) *pgx.Conn

func (*DB) GetDB

func (d *DB) GetDB() *sql.DB

func (*DB) GetReplicationConnection

func (d *DB) GetReplicationConnection(ctx context.Context) *pgx.Conn

func (*DB) MustExec

func (d *DB) MustExec(ctx context.Context, query string, args ...interface{})

func (*DB) Setup

func (d *DB) Setup(ctx context.Context, timeout time.Duration) (context.Context, func())

type Option

type Option func(*DB)

func (Option) And

func (o Option) And(other func(*DB)) Option

Jump to

Keyboard shortcuts

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