Documentation ¶
Index ¶
- Variables
- type Options
- type PropagationType
- type Transaction
- func (t *Transaction) Commit() error
- func (t *Transaction) Delete(query string, arg interface{}) error
- func (t *Transaction) GetOne(dest interface{}, query string, args ...interface{}) error
- func (t *Transaction) Insert(query string, arg interface{}) (int64, error)
- func (t *Transaction) Rollback() error
- func (t *Transaction) Select(dest interface{}, query string, args ...interface{}) error
- func (t *Transaction) String() string
- func (t *Transaction) Update(query string, arg interface{}) (int64, error)
- type TxManager
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidTxState is returned when transaction is not initialized ErrInvalidTxState = errors.New("gotx: tx is already committed or rolled back") )
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { // PropagationType specifies how the tx manager manages transaction propagation Propagation PropagationType IsolationLevel sql.IsolationLevel }
Options declares some configurable options when starts a transaction
type PropagationType ¶
type PropagationType uint8
PropagationType is an alias of uint8
const ( // Required specifies the txFunc will be run in an existing db tx. If there's no existing tx, // tx manager will create a new one for it. PropagationRequired PropagationType = iota // New specifies the txFunc will be run in a separated new db tx. PropagationNew )
constants that defines transaction propagation patterns
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is a logical transaction which wraps a underlying db transaction (physical transaction)
func (*Transaction) Commit ¶
func (t *Transaction) Commit() error
func (*Transaction) Delete ¶
func (t *Transaction) Delete(query string, arg interface{}) error
func (*Transaction) GetOne ¶
func (t *Transaction) GetOne(dest interface{}, query string, args ...interface{}) error
GetOne is the sqlx.Get wrapper
func (*Transaction) Insert ¶
func (t *Transaction) Insert(query string, arg interface{}) (int64, error)
Insert implements sql insert logic and returns generated ID
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error
rollback always do the real rollback. For tx binding to a unique db tx(requiredNew is true), rollback do the db rollback directly. For tx sharing a db tx, rollback do rollback only once.
func (*Transaction) Select ¶
func (t *Transaction) Select(dest interface{}, query string, args ...interface{}) error
func (*Transaction) String ¶
func (t *Transaction) String() string
func (*Transaction) Update ¶
func (t *Transaction) Update(query string, arg interface{}) (int64, error)
Update execute a update sql using sqlx NamedExec. Docs from sqlx doc:
Named queries are common to many other database packages. They allow you to use a bindvar syntax which refers to the names of struct fields or map keys to bind variables a query, rather than having to refer to everything positionally. The struct field naming conventions follow that of StructScan, using the NameMapper and the db struct tag.
type TxManager ¶
type TxManager struct {
// contains filtered or unexported fields
}
TxManager implements a basic transaction manager
func NewTxManager ¶
func (*TxManager) Remove ¶
func (tm *TxManager) Remove(trans *Transaction)