Documentation ¶
Index ¶
- Constants
- func Columns(i interface{}) []string
- func ValidateModel(ctx context.Context, f *Postgres, databaseName string, i interface{}) error
- func ValidateModels(ctx context.Context, f *Postgres, databaseName string, i ...interface{}) error
- type ConnOpt
- type ConnectionSettings
- func (cs *ConnectionSettings) Config() (*pgx.ConnConfig, error)
- func (cs *ConnectionSettings) Connect(ctx context.Context) (*pgx.Conn, error)
- func (cs *ConnectionSettings) Copy() *ConnectionSettings
- func (cs *ConnectionSettings) DSN() string
- func (cs *ConnectionSettings) PoolConfig() (*pgxpool.Config, error)
- func (cs *ConnectionSettings) String() string
- func (cs *ConnectionSettings) URL() string
- type Opt
- func OptExpireAfter(expireAfter uint) Opt
- func OptLogger(logger *zap.Logger) Opt
- func OptMounts(mounts []string) Opt
- func OptName(name string) Opt
- func OptNetworkName(networkName string) Opt
- func OptRepo(repo string) Opt
- func OptSettings(settings *ConnectionSettings) Opt
- func OptSkipTearDown() Opt
- func OptTimeoutAfter(timeoutAfter uint) Opt
- func OptVersion(version string) Opt
- type Postgres
- func (f *Postgres) Connect(ctx context.Context, opts ...ConnOpt) (*pgxpool.Pool, error)
- func (f *Postgres) CopyDatabase(ctx context.Context, source string, target string) error
- func (f *Postgres) CreateDatabase(ctx context.Context, name string) error
- func (f *Postgres) DropDatabase(ctx context.Context, name string) error
- func (f *Postgres) Dump(ctx context.Context, dir string, filename string) error
- func (f *Postgres) HostName() string
- func (f *Postgres) LoadSql(ctx context.Context, path string) error
- func (f *Postgres) LoadSqlPattern(ctx context.Context, pattern string) error
- func (f *Postgres) MustConnect(ctx context.Context, opts ...ConnOpt) *pgxpool.Pool
- func (f *Postgres) Ping(ctx context.Context) error
- func (f *Postgres) PingPsql(ctx context.Context) error
- func (f *Postgres) Psql(ctx context.Context, cmd []string, mounts []string, quiet bool) (int, error)
- func (p *Postgres) RecoverTearDown(ctx context.Context)
- func (f *Postgres) Restore(ctx context.Context, dir string, filename string) error
- func (f *Postgres) SetUp(ctx context.Context) error
- func (f *Postgres) Settings() *ConnectionSettings
- func (f *Postgres) TableColumns(ctx context.Context, database, schema, table string) ([]string, error)
- func (f *Postgres) TableExists(ctx context.Context, database, schema, table string) (bool, error)
- func (f *Postgres) Tables(ctx context.Context, database string) ([]string, error)
- func (p *Postgres) TearDown(ctx context.Context) error
- func (f *Postgres) WaitForReady(ctx context.Context, d time.Duration) error
Constants ¶
const ( DEFAULT_POSTGRES_REPO = "postgres" DEFAULT_POSTGRES_VERSION = "13-alpine" )
Variables ¶
This section is empty.
Functions ¶
func Columns ¶ added in v1.0.2
func Columns(i interface{}) []string
Given a struct, return the expected column names.
func ValidateModel ¶ added in v1.0.2
ValidateModel checks that a given struct is a valid representation of a database table.
- Validate table name (using gorm-style TableName() or name-to-snake)
- Validate columns exist.
func ValidateModels ¶ added in v1.0.2
ValidateModels checks that the given structs are valid representations of a database tables.
- Validate table name (using gorm-style TableName() or name-to-snake)
- Validate columns exist.
Types ¶
type ConnOpt ¶
type ConnOpt func(*connConfig)
func ConnOptCreateCopy ¶ added in v1.0.4
func ConnOptCreateCopy() ConnOpt
func ConnOptDatabase ¶ added in v1.0.4
func ConnOptRole ¶ added in v1.0.4
type ConnectionSettings ¶
type ConnectionSettings struct { Host string Port string User string Password string Database string DisableSSL bool MaxOpenConns int }
Since you shouldn't create a pgx.ConnConfig from scratch, ConnectionSettings exists to hold all the parameters we'll need to work with throughout the lifecycle of a postgres database throughout tests.
func (*ConnectionSettings) Config ¶
func (cs *ConnectionSettings) Config() (*pgx.ConnConfig, error)
func (*ConnectionSettings) Connect ¶
func (cs *ConnectionSettings) Connect(ctx context.Context) (*pgx.Conn, error)
func (*ConnectionSettings) Copy ¶
func (cs *ConnectionSettings) Copy() *ConnectionSettings
func (*ConnectionSettings) DSN ¶ added in v1.0.3
func (cs *ConnectionSettings) DSN() string
func (*ConnectionSettings) PoolConfig ¶
func (cs *ConnectionSettings) PoolConfig() (*pgxpool.Config, error)
func (*ConnectionSettings) String ¶
func (cs *ConnectionSettings) String() string
func (*ConnectionSettings) URL ¶ added in v1.0.3
func (cs *ConnectionSettings) URL() string
type Opt ¶
type Opt func(*Postgres)
func OptExpireAfter ¶
Tell docker to kill the container after an unreasonable amount of test time to prevent orphans. Defaults to 600 seconds.
func OptNetworkName ¶
func OptSettings ¶
func OptSettings(settings *ConnectionSettings) Opt
func OptSkipTearDown ¶
func OptSkipTearDown() Opt
func OptTimeoutAfter ¶
Wait this long for operations to execute. Defaults to 30 seconds.
func OptVersion ¶ added in v1.0.3
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
func (*Postgres) CopyDatabase ¶
CopyDatabase creates a copy of an existing postgres database using `createdb --template={source} {target}` source will default to the primary database
func (*Postgres) CreateDatabase ¶
func (*Postgres) DropDatabase ¶
func (*Postgres) LoadSql ¶
LoadSql runs a file or directory of *.sql files against the default postgres database.
func (*Postgres) LoadSqlPattern ¶
LoadSqlPattern finds files matching a custom pattern and runs them against the default database.
func (*Postgres) MustConnect ¶
func (*Postgres) RecoverTearDown ¶
func (*Postgres) Settings ¶
func (f *Postgres) Settings() *ConnectionSettings