# README
CRDB
crdb
is a wrapper around the logic for issuing SQL transactions which performs
retries (as required by CockroachDB).
Note that unfortunately there is no generic way of extracting a pg error code;
the library has to recognize driver-dependent error types. We currently use
the SQLState() string
method that is implemented in both
github.com/lib/pq
, since version 1.10.6, and
github.com/jackc/pgx
when used in database/sql
driver mode.
Subpackages provide support for gorm, pgx, and sqlx used in standalone-library mode.
Note for developers: if you make any changes here (especially if they modify public APIs), please verify that the code in https://github.com/cockroachdb/examples-go still works and update as necessary.
# Functions
Execute runs fn and retries it as needed.
ExecuteCtx runs fn and retries it as needed, respecting a maximum retry count obtained from the context.
ExecuteInTx runs fn inside tx.
ExecuteTx runs fn inside a transaction and retries it as needed.
ExecuteTxGenericTest represents the structure of a test for the ExecuteTx function.
WithMaxRetries configures context so that ExecuteTx retries tx specified number of times when encountering retryable errors.
# Structs
AmbiguousCommitError represents an error that left a transaction in an ambiguous state: unclear if it committed or not.
MaxRetriesExceededError represents an error caused by retying the transaction too many times, without it ever succeeding.
TxnRestartError represents an error when restarting a transaction.
# Interfaces
Tx abstracts the operations needed by ExecuteInTx so that different frameworks (e.g.
WriteSkewTest abstracts the operations that needs to be performed by a particular framework for the purposes of TestExecuteTx.
# Type aliases
ExecuteCtxFunc represents a function that takes a context and variadic arguments and returns an error.