stdpgxtxfx

package
v0.0.255 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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"`
	TxBeginSQL     stdtxpgxv5.TxBeginSQLFunc `optional:"true"`
	OnCommitTxHook stdtxpgxv5.TxOnCommitFunc `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.

Directories

Path Synopsis
Package stdpgxtxconnect runs connect-go v2 RPCs in a transaction from the transactors that [stdpgxtxfx] provides.
Package stdpgxtxconnect runs connect-go v2 RPCs in a transaction from the transactors that [stdpgxtxfx] provides.

Jump to

Keyboard shortcuts

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