stdpgxtxfx

package
v0.0.148 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package stdpgxtxfx provides database transactors.

Index

Constants

This section is empty.

Variables

View Source
var PgErrorsToConnectError = map[string]func(lpgErr *pgconn.PgError, logs *zap.Logger) error{
	"42501": func(pgErr *pgconn.PgError, logs *zap.Logger) error {
		logs.Info("database permission denied", zap.Error(pgErr))
		return connect.NewError(connect.CodePermissionDenied, errors.New("database permission denied"))
	},
}

PgErrorsToConnectError statically defines how database errors are mapped to connect errors.

Functions

func BHJTx added in v0.0.146

func BHJTx[C bhttp.Context, I, O any](
	txr *stdtx.Transactor[pgx.Tx],
	fn func(context.Context, *zap.Logger, pgx.Tx, *I) (*O, error),
) bhttp.HandlerFunc[C]

BHJTx creates an bhttp handler that transacts on json request and response.

func CTx added in v0.0.144

func CTx[I, O any](
	ctx context.Context,
	txr *stdtx.Transactor[pgx.Tx],
	req *connect.Request[I],
	fn func(context.Context, *zap.Logger, pgx.Tx, *I) (*O, error),
) (*connect.Response[O], error)

CTx transacts while returning a protobuf message for the response. It is a shorthant for the most common scenario in our connect RPC code and makes it way more succinct.

func HJTx added in v0.0.145

func HJTx[I, O any](
	ctx context.Context,
	txr *stdtx.Transactor[pgx.Tx],
	resp http.ResponseWriter,
	req *http.Request,
	fn func(context.Context, *zap.Logger, pgx.Tx, *I) (*O, error),
) error

HJTx transacts while encoding and decoding a buffered JSON HTTP request/response.

func Provide

func Provide(applicationName string) fx.Option

Provide provides the standard read-write/read-only separation.

func TestProvide

func TestProvide(applicationName, endRoleUsername, endRolePassword string) fx.Option

TestProvide provides project-specific transactor config to make it easy for any test package to interact with the database.

Types

type Config

type Config struct {
	TestMaxQueryCosts float64 `env:"TEST_MAX_QUERY_COSTS"`
}

Config configures the transact components.

type Params

type Params struct {
	fx.In
	Config
	RW     *pgxpool.Pool             `name:"rw"`
	RO     *pgxpool.Pool             `name:"ro"`
	TxHook stdtxpgxv5.TxBeginSQLFunc `optional:"true"`
}

Params describe fx params for creating the transactors.

type Result

type Result struct {
	fx.Out
	ReadWrite *stdtx.Transactor[pgx.Tx] `name:"rw"`
	ReadOnly  *stdtx.Transactor[pgx.Tx] `name:"ro"`
}

Result describes the fx components this package produces.

func New

func New(params Params) (Result, error)

New provides the transactors.

Jump to

Keyboard shortcuts

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