Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // UnitLogger specifies the option to provide a logger for the work unit. UnitLogger = func(l *zap.Logger) Option { return func(o *UnitOptions) { o.Logger = l } } // UnitScope specifies the option to provide a metric scope for the work unit. UnitScope = func(s tally.Scope) Option { return func(o *UnitOptions) { o.Scope = s } } )
var ( // ErrMissingDataMapper represents the error that is returned // when attempting to add, alter, remove, or register an entity // that doesn't have a corresponding data mapper. ErrMissingDataMapper = errors.New("missing data mapper for entity") )
Functions ¶
This section is empty.
Types ¶
type DataMapper ¶
type DataMapper interface {
Insert(...interface{}) error
Update(...interface{}) error
Delete(...interface{}) error
}
DataMapper represents a creator, modifier, and deleter of entities.
type Option ¶
type Option func(*UnitOptions)
Option applies an option to the provided configuration.
type SQLDataMapper ¶
type SQLDataMapper interface {
Insert(*sql.Tx, ...interface{}) error
Update(*sql.Tx, ...interface{}) error
Delete(*sql.Tx, ...interface{}) error
}
SQLDataMapper represents a creator, modifier, and deleter of entities persisted in SQL data stores.
type TypeName ¶
type TypeName string
TypeName represents an entity's type.
func TypeNameOf ¶
func TypeNameOf(entity interface{}) TypeName
TypeNameOf provides the type name for the provided entity.
type Unit ¶
type Unit interface {
// Register tracks the provided entities as clean.
Register(...interface{}) error
// Add marks the provided entities as new additions.
Add(...interface{}) error
// Alter marks the provided entities as modifications.
Alter(...interface{}) error
// Remove marks the provided entities as removals.
Remove(...interface{}) error
// Save commits the new additions, modifications, and removals
// within the work unit to a persistent store.
Save() error
}
Unit represents an atomic set of entity changes.
func NewBestEffortUnit ¶
func NewBestEffortUnit( mappers map[TypeName]DataMapper, options ...Option) (Unit, error)
NewBestEffortUnit constructs a work unit that when faced with adversity, attempts rollback a single time.
func NewSQLUnit ¶
NewSQLUnit constructs a work unit for SQL data stores.
type UnitOptions ¶
UnitOptions represents the configuration options for the work unit.
type Uniter ¶
Uniter represents a factory for work units.
func NewBestEffortUniter ¶
func NewBestEffortUniter( mappers map[TypeName]DataMapper, options ...Option) Uniter
NewBestEffortUniter constructs a new best effort unit factory.
func NewSQLUniter ¶
NewSQLUniter constructs a new SQL work unit factory.
