stdpgxtxconnect

package
v0.0.249 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 8 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 stdpgxtxconnect runs connect-go v2 RPCs in a transaction from the transactors that [stdpgxtxfx] provides. It is the v2 counterpart of [stdpgxtxfx.CTx], which takes connect-go v1 requests.

Index

Constants

This section is empty.

Variables

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

PgErrorsToConnectError statically defines how database errors are mapped to connect errors. The database error is attached as the cause: visible to errors.Is and errors.As on the server, but never sent to the client.

Functions

func CTx

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

CTx runs fn in a transaction from txr and returns its response message. It is a shorthand for the most common scenario in our connect RPC code. The transaction commits when fn returns no error and rolls back otherwise. A *connect.Error that fn returns is returned as is, so it reaches the client; database errors listed in PgErrorsToConnectError are mapped, and other errors are returned as stdtx returns them. stdtx retries fn when the transaction fails to serialize, so fn must be safe to run more than once. The context must carry a logger, see stdctx.WithLogger.

Types

This section is empty.

Jump to

Keyboard shortcuts

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