pg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: MIT Imports: 15 Imported by: 4

Documentation

Index

Constants

View Source
const (
	JobLockStateNone     = ""
	JobLockStateHeld     = "held"
	JobLockStateLost     = "lost"
	JobLockStateReleased = "released"
)

Variables

This section is empty.

Functions

func BigintOrNull

func BigintOrNull(n int64) pgtype.Int8

func IsConstraintError

func IsConstraintError(err error, constraint string) bool

IsConstraintError checks if an error was caused by a specific constraint violation.

func SafeRollback

func SafeRollback(
	ctx context.Context, logger *slog.Logger, tx pgx.Tx, txName string,
)

SafeRollback rolls back a transaction and logs if the rollback fails. If the transaction already has been closed it's not treated as an error.

func SetConnStringVariables

func SetConnStringVariables(conn string, vars url.Values) (string, error)

SetConnStringVariables parses a connection string URI and adds the given query string variables to it.

func TextOrNull

func TextOrNull(s string) pgtype.Text

func Time

func Time(t time.Time) pgtype.Timestamptz

func TimeOrNull

func TimeOrNull(t time.Time) pgtype.Timestamptz

func WithTX

func WithTX(
	ctx context.Context, logger *slog.Logger, pool TransactionBeginner,
	name string, fn func(tx pgx.Tx) error,
) error

Types

type JobLock

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

func NewJobLock

func NewJobLock(
	db *pgxpool.Pool, logger *slog.Logger, name string,
	pingInterval, staleAfter, checkInterval, timeout time.Duration,
) (*JobLock, error)

func (*JobLock) RunWithContext

func (jl *JobLock) RunWithContext(
	ctx context.Context,
	fn func(ctx context.Context) error,
) error

func (*JobLock) Stop

func (jl *JobLock) Stop()

type JobLockState

type JobLockState string

type TransactionBeginner

type TransactionBeginner interface {
	Begin(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