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 ¶
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.