pg

package
v1.13.20 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyInTx              = errors.New("already executing in existing db tx")
	ErrNotInTx                  = errors.New("not executing in existing db tx")
	ErrInvalidPool              = errors.New("provided pgx pool is not the global pool")
	ErrGlobalPoolNotInitialized = errors.New("global pgx pool is not initialized")
)

Functions

func Decode

func Decode(value string) ([]byte, error)

Decode decodes the input string by automatically determining the encoding type from its short prefix.

func Encode

func Encode(value []byte, encodeType ...EncodeType) string

Encode encodes the input byte slice into the specified format, prefixed with a short encoding type. If no encodeType is provided, it defaults to Base64.

func ExecuteInTx

func ExecuteInTx(ctx context.Context, pool *pgxpool.Pool, fn func(tx pgx.Tx) error) (err error)

ExecuteInTx is meant for DB store implementations to execute an operation within the scope of a DB transaction. This method is aware of ExecuteTxWithinCtx, and will dynamically decide when to use a new or existing transaction, as well as where the responsibilty for commit/rollback calls lie.

func ExecuteTxWithinCtx

func ExecuteTxWithinCtx(ctx context.Context, fn func(context.Context) error) error

ExecuteTxWithinCtx executes a DB transaction that's scoped to a call to fn. The transaction is passed along with the context. Once fn is complete, commit/rollback is called based on whether an error is returned.

func NewWithUsernameAndPassword

func NewWithUsernameAndPassword(username, password, hostname, port, dbname string) (*sql.DB, error)

Get a DB connection pool using username/password credentials

func SetupGlobalPgxPool added in v1.6.0

func SetupGlobalPgxPool(pool *pgxpool.Pool)

Types

type Config

type Config struct {
	User               string
	Host               string
	Password           string
	Port               int
	DbName             string
	MaxOpenConnections int
	MaxIdleConnections int
}

type EncodeType

type EncodeType string

EncodeType is an enum-like type for encoding types.

const (
	Base64            EncodeType = "b64"
	Base58            EncodeType = "b58"
	Hex               EncodeType = "hex"
	DefaultEncodeType            = Base64
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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