uow

package
v0.8.14-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
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

type Contextual interface {
	Context(interface{}) context.Context
}

Contextual returns a context for a given argument.

type Transactional

type Transactional interface {
	Begin() (Tx, error)
}

Transactional begins a transaction

type Tx

type Tx interface {
	Commit() error
	Rollback() error
}

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

Jump to

Keyboard shortcuts

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