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 ¶
This section is empty.
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), mappers ...stdcrpcintercept.ErrorMapper, ) (*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. 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.
CTx maps the error of the transaction with the first rule that applies:
- a *connect.Error that fn returns is returned as is, so it reaches the client;
- each of mappers in turn, until one returns an error, as stdcrpcintercept.NewServerErrors runs them; pass them to map the errors of this RPC only, such as a unique violation to the ALREADY_EXISTS of the resource it creates, and to the server interceptor for errors that recur across RPCs;
- a serialization failure or deadlock (SQLSTATE 40001 or 40P01) that remains after stdtx ran out of retries becomes ABORTED, the code for a concurrency conflict that the client may retry;
- other errors are returned as stdtx returns them, for the server's error interceptor to map.
Types ¶
This section is empty.