Documentation ¶
Index ¶
- Variables
- func DbConnect(ctx context.Context, logger *zap.Logger, config Configuration) (*sql.DB, string)
- func ExecuteInTx(ctx context.Context, tx Tx, fn func() error) (err error)
- func ExecuteRetryable(fn func() error) error
- func StatusError(code codes.Code, msg string, cause error) error
- type AmbiguousCommitError
- type Configuration
- type ErrorCauser
- type Scannable
- type Tx
- type TxnRestartError
Constants ¶
This section is empty.
Variables ¶
var ErrDatabaseDriverMismatch = errors.New("database driver mismatch")
var ErrRowsAffectedCount = errors.New("rows_affected_count")
Functions ¶
func ExecuteInTx ¶
ExecuteInTx runs fn inside tx which should already have begun. *WARNING*: Do not execute any statements on the supplied tx before calling this function. ExecuteInTx will only retry statements that are performed within the supplied closure (fn). Any statements performed on the tx before ExecuteInTx is invoked will *not* be re-run if the transaction needs to be retried.
fn is subject to the same restrictions as the fn passed to ExecuteTx.
func ExecuteRetryable ¶
ExecuteRetryable Retry functions that perform non-transactional database operations.
Types ¶
type AmbiguousCommitError ¶
type AmbiguousCommitError struct {
// contains filtered or unexported fields
}
AmbiguousCommitError represents an error that left a transaction in an ambiguous state: unclear if it committed or not.
type Configuration ¶
type Configuration struct { Addresses []string `` /* 135-byte string literal not displayed */ ConnMaxLifetimeMs int `` /* 199-byte string literal not displayed */ MaxOpenConns int `yaml:"max_open_conns" json:"max_open_conns" usage:"Maximum number of allowed open connections to the database. Default 100."` MaxIdleConns int `` /* 135-byte string literal not displayed */ DnsScanIntervalSec int `` /* 171-byte string literal not displayed */ }
Configuration 配置
func NewConfiguration ¶
func NewConfiguration() Configuration
NewConfiguration creates a new Configuration struct.
type ErrorCauser ¶
type ErrorCauser interface { // Cause returns the proximate cause of this error. Cause() error }
ErrorCauser is the type implemented by an error that remembers its cause.
ErrorCauser is intentionally equivalent to the causer interface used by the github.com/pkg/errors package.
type Scannable ¶
type Scannable interface {
Scan(dest ...interface{}) error
}
Scannable Interface to help utility functions accept either *sql.Row or *sql.Rows for scanning one row at a time.
type Tx ¶
type Tx interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) Commit() error Rollback() error }
Tx is used to permit clients to implement custom transaction logic.
type TxnRestartError ¶
type TxnRestartError struct {
// contains filtered or unexported fields
}
TxnRestartError represents an error when restarting a transaction. `cause` is the error from restarting the txn and `retryCause` is the original error which triggered the restart.
func (*TxnRestartError) Cause ¶
func (e *TxnRestartError) Cause() error
Cause implements the ErrorCauser interface.
func (*TxnRestartError) Error ¶
func (e *TxnRestartError) Error() string
Error implements the error interface.
func (*TxnRestartError) RetryCause ¶
func (e *TxnRestartError) RetryCause() error
RetryCause returns the error that caused the transaction to be restarted.