database

package
v0.0.0-...-7a25296 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDatabaseDriverMismatch = errors.New("database driver mismatch")
View Source
var ErrRowsAffectedCount = errors.New("rows_affected_count")

Functions

func DbConnect

func DbConnect(ctx context.Context, logger *zap.Logger, config Configuration) (*sql.DB, string)

func ExecuteInTx

func ExecuteInTx(ctx context.Context, tx Tx, fn func() error) (err error)

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

func ExecuteRetryable(fn func() error) error

ExecuteRetryable Retry functions that perform non-transactional database operations.

func StatusError

func StatusError(code codes.Code, msg string, cause error) error

Helper function for creating status errors that wrap underlying causes, usually DB errors.

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.

func (*AmbiguousCommitError) Cause

func (e *AmbiguousCommitError) Cause() error

Cause implements the ErrorCauser interface.

func (*AmbiguousCommitError) Error

func (e *AmbiguousCommitError) Error() string

Error implements the error interface.

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.

Jump to

Keyboard shortcuts

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