db

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxOpenConnections    = 25
	DefaultMaxIdleConnections    = 25
	DefaultConnectionMaxLifetime = 5 * time.Minute
	DatabaseDriver               = "pgx"
)
View Source
const (
	SerializationRetryMaxAttempts   = 10
	SerializationRetryStartInterval = time.Millisecond * 2
)

Variables

View Source
var (
	ErrNotFound      = fmt.Errorf("not found: %w", pgx.ErrNoRows)
	ErrAlreadyExists = errors.New("already exists")
	ErrSerialization = errors.New("serialization error")
	ErrNotASlice     = errors.New("results must be a pointer to a slice")
)
View Source
var ErrSchemaNotCompatible = errors.New("db schema version not compatible with latest version")

Functions

func ConnectDBPool added in v0.16.0

func ConnectDBPool(p params.Database) (*pgxpool.Pool, error)

ConnectDBPool connects to a database using the database params and returns a connection pool

func GetLastMigrationAvailable

func GetLastMigrationAvailable() (uint, error)

func IsSerializationError

func IsSerializationError(err error) bool

func IsUniqueViolation

func IsUniqueViolation(err error) bool

func MigrateDown

func MigrateDown(params params.Database) error

func MigrateTo

func MigrateTo(p params.Database, version uint, force bool) error

func MigrateUp

func MigrateUp(p params.Database) error

func MigrateVersion

func MigrateVersion(params params.Database) (uint, bool, error)

func Ping added in v0.16.0

func Ping(ctx context.Context, pool *pgxpool.Pool) error

func Prefix

func Prefix(prefix string) string

func Select added in v0.16.0

func Select(d Tx, results interface{}, query string, args ...interface{}) error

func ValidateSchemaUpToDate added in v0.11.0

func ValidateSchemaUpToDate(params params.Database) error

Types

type Database

type Database interface {
	Tx
	Close()
	Transact(fn TxFunc, opts ...TxOpt) (interface{}, error)
	Metadata() (map[string]string, error)
	Stats() sql.DBStats
	WithContext(ctx context.Context) Database
	Pool() *pgxpool.Pool
}

func BuildDatabaseConnection added in v0.9.0

func BuildDatabaseConnection(dbParams params.Database) Database

BuildDatabaseConnection returns a database connection based on a pool for the configuration in c.

func ConnectDB

func ConnectDB(p params.Database) (Database, error)

ConnectDB connects to a database using the database params and returns Database

type DatabaseMigrator

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

func NewDatabaseMigrator

func NewDatabaseMigrator(params params.Database) *DatabaseMigrator

func (*DatabaseMigrator) Migrate

func (d *DatabaseMigrator) Migrate(ctx context.Context) error

type Migrator

type Migrator interface {
	Migrate(ctx context.Context) error
}

type PgxDatabase added in v0.16.0

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

func NewPgxDatabase added in v0.16.0

func NewPgxDatabase(db *pgxpool.Pool) *PgxDatabase

func (*PgxDatabase) Close added in v0.16.0

func (d *PgxDatabase) Close()

func (*PgxDatabase) Exec added in v0.16.0

func (d *PgxDatabase) Exec(query string, args ...interface{}) (pgconn.CommandTag, error)

func (*PgxDatabase) Get added in v0.16.0

func (d *PgxDatabase) Get(dest interface{}, query string, args ...interface{}) error

func (*PgxDatabase) GetPrimitive added in v0.16.0

func (d *PgxDatabase) GetPrimitive(dest interface{}, query string, args ...interface{}) error

func (*PgxDatabase) Metadata added in v0.16.0

func (d *PgxDatabase) Metadata() (map[string]string, error)

func (*PgxDatabase) Pool added in v0.16.0

func (d *PgxDatabase) Pool() *pgxpool.Pool

func (*PgxDatabase) Query added in v0.16.0

func (d *PgxDatabase) Query(query string, args ...interface{}) (rows pgx.Rows, err error)

func (*PgxDatabase) Select added in v0.16.0

func (d *PgxDatabase) Select(results interface{}, query string, args ...interface{}) error

func (*PgxDatabase) Stats added in v0.16.0

func (d *PgxDatabase) Stats() sql.DBStats

func (*PgxDatabase) Transact added in v0.16.0

func (d *PgxDatabase) Transact(fn TxFunc, opts ...TxOpt) (interface{}, error)

func (*PgxDatabase) WithContext added in v0.16.0

func (d *PgxDatabase) WithContext(ctx context.Context) Database

type QueryOptions added in v0.9.0

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

type Tx

type Tx interface {
	Query(query string, args ...interface{}) (pgx.Rows, error)
	Select(dest interface{}, query string, args ...interface{}) error
	Get(dest interface{}, query string, args ...interface{}) error
	GetPrimitive(dest interface{}, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (pgconn.CommandTag, error)
}

type TxFunc

type TxFunc func(tx Tx) (interface{}, error)

func Void added in v0.17.0

func Void(fn func(tx Tx) error) TxFunc

Void wraps a procedure with no return value as a TxFunc

type TxOpt

type TxOpt func(*TxOptions)

func ReadCommitted added in v0.16.0

func ReadCommitted() TxOpt

func ReadOnly

func ReadOnly() TxOpt

func RepeatableRead added in v0.16.0

func RepeatableRead() TxOpt

func WithContext

func WithContext(ctx context.Context) TxOpt

func WithIsolationLevel

func WithIsolationLevel(level pgx.TxIsoLevel) TxOpt

func WithLogger

func WithLogger(logger logging.Logger) TxOpt

type TxOptions

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

func DefaultTxOptions

func DefaultTxOptions() *TxOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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