repository

package
v0.0.0-...-5b8d9f6 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Repository) error

Option provides functional configuration for a *Repository

func WithEvents

func WithEvents(events ...es.Event) Option

WithEvents binds one or more events to the Serializer. If you choose not to use the default serializer you need to provide the WithSerializer option before this option or the events will be bound to the default serializer instead of the one you later specify.

func WithObservers

func WithObservers(observers ...func(event es.Event)) Option

WithObservers allows observers to watch the saved events; Observers should invoke very short lived operations as calls will block until the observer is finished

func WithSerializer

func WithSerializer(serializer es.Serializer) Option

WithSerializer specifies the serializer to be used.

func WithStore

func WithStore(store es.Store) Option

WithStore may be used to configure a new store.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository provides the primary abstraction to saving and loading events

func New

func New(prototype es.Aggregate, events []es.Event, opts ...Option) (*Repository, error)

New creates a new Repository using defaults and then applying any operations.

Defaults

A repository is built with the following defaults:

  • Memory store
  • Gob serializer

func (*Repository) Apply

func (r *Repository) Apply(ctx context.Context, command es.Command) (int64, error)

Apply executes the command specified and returns the current version of the aggregate

func (*Repository) Load

func (r *Repository) Load(ctx context.Context, aggregateID string) (es.Aggregate, error)

Load retrieves the specified aggregate from the underlying store

func (*Repository) New

func (r *Repository) New() es.Aggregate

New returns a new instance of the aggregate

func (*Repository) Save

func (r *Repository) Save(ctx context.Context, events ...es.Event) error

Save persists the events into the underlying Store

func (*Repository) Serializer

func (r *Repository) Serializer() es.Serializer

Serializer returns the underlying serializer

func (*Repository) Store

func (r *Repository) Store() es.Store

Store returns the underlying Store

Jump to

Keyboard shortcuts

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