dbpgx

package
v0.0.0-...-cbbd1a2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DbErrRuntimeEnvironment        = errx.NewKind("DbErrRuntimeEnvironment")
	DbErrInternalAppError          = errx.NewKind("DbErrInternalAppError")
	DbErrConnectionException       = errx.NewKind("DbErrConnectionException")
	DbErrConstraintViolation       = errx.NewKind("DbErrConstraintViolation")
	DbErrUniqueViolation           = errx.NewKind("DbErrUniqueViolation", DbErrConstraintViolation)
	DbErrInsufficientResources     = errx.NewKind("DbErrInsufficientResources", DbErrRuntimeEnvironment)
	DbErrOperatorIntervention      = errx.NewKind("DbErrOperatorIntervention", DbErrRuntimeEnvironment)
	DbErrExternalSystemError       = errx.NewKind("DbErrExternalSystemError", DbErrRuntimeEnvironment)
	DbErrEngineError               = errx.NewKind("DbErrEngineError", DbErrRuntimeEnvironment)
	DbErrRecordNotFound            = errx.NewKind("DbErrRecordNotFound")
	DbErrUnexpectedMultipleRecords = errx.NewKind("DbErrUnexpectedMultipleRecords", DbErrInternalAppError)
)

Functions

func ClassifyError

func ClassifyError(err error) *errx.Kind

ClassifyError returns an database-related *errx.Kind that corresponds to err.

func DeferredRollback

func DeferredRollback(ctx context.Context, tx pgx.Tx)

func ReadMany

func ReadMany[R any](
	ctx context.Context,
	tx pgx.Tx,
	mainSql string,
	limit int,
	offset int,
	args ...any,
) ([]R, error)

ReadMany reads an array of records from the database. `mainSql` is the main query string, which is appended with optional limit and offset clauses. If limit or offset is negative then the corresponding clause is not appended.

func ReadSingle

func ReadSingle[R any, F any](
	ctx context.Context,
	tx pgx.Tx,
	tableName string,
	fieldName string,
	fieldValue F,
	record *R,
) error

ReadSingle reads a single record from a table.

func SflWithTransaction

func SflWithTransaction[R, S, T any](
	db Db,
	block func(ctx context.Context, tx pgx.Tx, reqCtx R, in S) (T, error),
) func(ctx context.Context, reqCtx R, in S) (T, error)

func SqlState

func SqlState(err error) string

SqlState returns the the pgx SQLState() of err if err is wraps a *pgconn.PgError, returns the empty string otherwise.

func WithTransaction

func WithTransaction[T any](
	db Db,
	ctx context.Context,
	block func(ctx context.Context, tx pgx.Tx) (T, error),
) (T, error)

Types

type Db

type Db struct {
	Pool *pgxpool.Pool
}

func (Db) Acquire

func (s Db) Acquire(ctx context.Context) (*pgxpool.Conn, error)

func (Db) BeginTx

func (s Db) BeginTx(ctx context.Context) (pgx.Tx, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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