db

package
v0.0.0-...-d3b47b8 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldsSlice

type FieldsSlice []string

func FieldNames

func FieldNames(tx *sqlx.Tx, arg interface{}) (FieldsSlice, error)

FieldNames returns the current list of fields associated with a type. By using the sqlx.Tx, we can use the existing reflection mapper functionality to get the field names back.

func (FieldsSlice) Join

func (f FieldsSlice) Join() string

type SQLDatabase

type SQLDatabase struct {
	// contains filtered or unexported fields
}

SQLDatabase creates a new SQL Database for handling transactions with the required retry semantics.

func NewSQLDatabase

func NewSQLDatabase(db *sql.DB, driverName string) *SQLDatabase

NewSQLDatabase creates a new SQLDatabase from a given *sql.DB

func (*SQLDatabase) CreateTxn

func (s *SQLDatabase) CreateTxn(ctx context.Context) (TxnBuilder, error)

CreateTxn creates a transaction builder. The transaction builder accumulates a series of functions that can be executed on a given commit.

func (*SQLDatabase) Run

func (s *SQLDatabase) Run(fn func(context.Context, *sqlx.Tx) error) error

Run is a convince function for running one shot transactions, which correctly handles the rollback semantics and retries where available. The run function maybe called multiple times if the transaction is being retried.

type TxnBuilder

type TxnBuilder interface {
	Stage(func(context.Context, *sqlx.Tx) error) TxnBuilder
	Commit() error
}

TxnBuilder allows the building of a series of functions that will be called during a transaction commit. Only upon commit is the transaction constructed and the function called. The functions in the txn builder maybe called multiple times depending on how many retries are employed.

Jump to

Keyboard shortcuts

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