Documentation ¶
Index ¶
Constants ¶
const ( // InMemoryContextKey is the context key that must be shared among multiple // reporitories involved in a UnitOfWork transaction InMemoryContextKey = iota )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextProvider ¶
type ContextProvider interface {
ContextKey() interface{}
}
ContextProvider returns a context key
type Contextual ¶
Contextual returns a context for a given argument.
type Transactional ¶
Transactional begins a transaction
type Tx ¶
Tx represents an all-or-nothing transaction, by committing or rolling back a set of read/write operations
type UnitOfWork ¶
type UnitOfWork struct {
// contains filtered or unexported fields
}
UnitOfWork allows to run multiple transactions as one
func NewUnitOfWork ¶
func NewUnitOfWork(repositories ...Transactional) *UnitOfWork
NewUnitOfWork returns a new UnitOfWork with the given Transaction interfaces
func (*UnitOfWork) Context ¶
func (u *UnitOfWork) Context(repository interface{}) context.Context
Context returns the context for the given argument.
func (*UnitOfWork) Run ¶
func (u *UnitOfWork) Run(fn func(Contextual) error) (err error)
Run executes the given function over the current UnitOfWork. The given function is likely making read/write operations to different repositories in a transactional way. Run makes sure that all the transactions within the given function are either all committed to the relative storage or rolled back if any error occur