Documentation
¶
Overview ¶
Package tx provides a simple implementation agnostic transaction abstraction
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run runs provided func as a transaction
Non nil error returned by the function is considered to indicate that the transaction should be rolled back, accordingly, nil error indicates that the transaction should be commited by calling Commit and Rollback methods on a registered repository respectively
Types ¶
type SQL ¶
SQL is a sql implementation of Transactional interface It is meant to be used as a helper and embedded inside of data access objects such as a repositories in order to provide them with decoupled sql transaction behavior
type Transactional ¶
type Transactional interface { // return tx.Run(ctx, ur, transaction, f) // } RunTx(context.Context, func(context.Context) error) error // Commit is called every time RunTx transaction func returns nil error // indicating that transaction shuld be commited // // If Commit returns an error it is propagated and returned by RunTx // // Commit should never be called directly by client code Commit(*Tx) error // Rollback is called every time RunTx transaction func // returns an error indicating that transaction should be aborted // // If Rollback returns an error it wraps the error returned from // transaction func and both are propagated and returned by RunT // // Rollback should never be called directly by client code Rollback(*Tx) error }
Transactional interface should be implemented by an object wanting to use transactions
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx represents transaction object
func Current ¶
Current extracts Tx object from context if any Returns nil, false if not in a transaction