startup_postgres

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTransaction = errors.New("no transaction in context")

Functions

func ContextWithTransaction added in v1.1.0

func ContextWithTransaction(ctx context.Context, tx *sqlx.Tx) context.Context

Puts a transaction into a context and returns the new context with the transaction

func ErrIsForeignKeyViolation

func ErrIsForeignKeyViolation(err error) bool

func ErrIsUniqueViolation

func ErrIsUniqueViolation(err error) bool

func NewTransactionContext added in v1.1.0

func NewTransactionContext(ctx context.Context, db BeginTxer, operation TransactionFn) (err error)

Creates a new transaction, puts it into the context and runs the given operation with the context and the transaction.

func TransactionFromContext added in v1.1.0

func TransactionFromContext(ctx context.Context) *sqlx.Tx

Gets the current transaction from the context

func WithTransaction

func WithTransaction(db BeginTxer, fn func(tx *sqlx.Tx) error) (err error)

Ends the given transaction. This method will either commit the transaction if the given recoverValue is nil, or rollback the transaction if it is non nil.

func WithTransactionFromContext added in v1.1.0

func WithTransactionFromContext(ctx context.Context, operation func(tx *sqlx.Tx) error) error

Calls the given operation with the transaction that is currently stored in the context. Will fail with ErrNoTransaction if there is no transaction stored in the context.

Types

type BeginTxer added in v1.0.2

type BeginTxer interface {
	Beginx() (*sqlx.Tx, error)
	BeginTxx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error)
}

type Helper

type Helper struct {
	*sqlx.DB
}

func New

func New(db *sqlx.DB) Helper

func (*Helper) WithTransaction added in v1.0.1

func (h *Helper) WithTransaction(fn func(tx *sqlx.Tx) error) (err error)

type Initializer

type Initializer func(db *sqlx.DB) error

func DefaultMigration

func DefaultMigration(table string) Initializer

Creates an Initializer that performs a database migration by looking for sql files in the default directories.

func Migration

func Migration(table, directory string) Initializer

Runs a migration with the sql files from the given directory. The directory must exist. The migration library will use the given table name to store the migration progress

type PostgresOptions

type PostgresOptions struct {
	URL      string `long:"postgres" default:"postgres://postgres:postgres@localhost:5432?sslmode=disable" description:"Postgres server url."`
	PoolSize int    `` /* 133-byte string literal not displayed */

	ConnectionLifetime time.Duration `long:"postgres-lifetime" default:"10m" description:"Maximum time a connection in the pool can be used."`

	Inputs struct {
		// the driver name to use. If this is empty,
		// we select the default of 'postgres' or 'pgx',
		// depending on availability
		DriverName string

		// An optional initializer. This might be used to do
		// database migration or stuff.
		Initializer Initializer
	}
	// contains filtered or unexported fields
}

func (*PostgresOptions) Connection

func (opts *PostgresOptions) Connection() *sqlx.DB

func (*PostgresOptions) StartVacuumTask

func (opts *PostgresOptions) StartVacuumTask(db *sqlx.DB, table string, interval time.Duration, clock clock.Clock) io.Closer

type TransactionFn added in v1.1.0

type TransactionFn func(ctx context.Context, tx *sqlx.Tx) error

Jump to

Keyboard shortcuts

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