pg

package
v0.0.0-...-d552a0f Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExponentialBackOff

func ExponentialBackOff(maxRetries uint64, maxElapsedTime time.Duration) backoff.BackOff

ExponentialBackOff returns the exponential backoff configuration based on Azure best practices Reference: https://docs.microsoft.com/en-us/azure/postgresql/concepts-connectivity#handling-transient-errors

func Tx

func Tx(ctx context.Context, dbconn BeginnerExecutor, callback func(ContextExecutor) error) error

Tx starts a transaction

func TxWithBackOff

func TxWithBackOff(ctx context.Context, b backoff.BackOff, dbconn BeginnerExecutor, callback func(ContextExecutor) error) error

TxWithBackOff starts a transaction with the provided backoff policy

Types

type Beginner

type Beginner interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Transactor, error)
}

Beginner allows creation of context aware transactions with options.

type BeginnerExecutor

type BeginnerExecutor interface {
	Beginner
	ContextExecutor

	Close() error
	InstanceInfo() InstanceInfo
}

BeginnerExecutor can context-aware perform SQL queries and create context-aware transactions with options

func NewPool

func NewPool(
	url string,
	poolMaxOpenConns,
	poolMaxIdleConns int,
) (BeginnerExecutor, error)

NewPool opens a new DB connection pool, pings it and returns the pool connection pool definition: http://go-database-sql.org/connection-pool.html

type ContextExecutor

type ContextExecutor interface {
	Executor

	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

ContextExecutor can perform SQL queries with context

type Executor

type Executor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Executor can perform SQL queries.

type InstanceInfo

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

InstanceInfo holds info about the DB

type Transactor

type Transactor interface {
	Commit() error
	Rollback() error
	ContextExecutor
}

Transactor is an interface for a sql.Tx

Jump to

Keyboard shortcuts

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