aggregate

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MPL-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(ctx context.Context, es core.EventStore, id string, a aggregate) error

Load returns the aggregate based on its events

func LoadFromSnapshot

func LoadFromSnapshot(ctx context.Context, es core.EventStore, ss core.SnapshotStore, id string, as aggregateSnapshot) error

LoadFromSnapshot fetch the aggregate by first get its snapshot and later append events after the snapshot was stored This can speed up the load time of aggregates with many events

func LoadSnapshot

func LoadSnapshot(ctx context.Context, ss core.SnapshotStore, id string, s snapshot) error

LoadSnapshot build the aggregate based on its snapshot data not including its events. Beware that it could be more events that has happened after the snapshot was taken

func Register

func Register(a aggregate)

Register registers the aggregate and its events

func Save

func Save(es core.EventStore, a aggregate) error

Save stores the aggregate events in the supplied event store

func SaveSnapshot

func SaveSnapshot(ss core.SnapshotStore, s snapshot) error

SaveSnapshot will only store the snapshot and will return an error if there are events that are not stored

func SetIDFunc

func SetIDFunc(f func() string)

SetIDFunc is used to change how aggregate ID's are generated default is a random string

func TrackChange

func TrackChange(a aggregate, data interface{})

TrackChange is used internally by behaviour methods to apply a state change to the current instance and also track it in order that it can be persisted later.

func TrackChangeWithMetadata

func TrackChangeWithMetadata(a aggregate, data interface{}, metadata map[string]interface{})

TrackChangeWithMetadata is used internally by behaviour methods to apply a state change to the current instance and also track it in order that it can be persisted later. meta data is handled by this func to store none related application state

Types

type RegisterFunc

type RegisterFunc = func(events ...interface{})

type Root

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

Root to be included into aggregates to give it the aggregate root behaviors

func (*Root) Events

func (ar *Root) Events() []eventsourcing.Event

Events return the aggregate events from the aggregate make a copy of the slice preventing outsiders modifying events.

func (*Root) GlobalVersion

func (ar *Root) GlobalVersion() eventsourcing.Version

GlobalVersion returns the global version based on the last stored event

func (*Root) ID

func (ar *Root) ID() string

ID returns the aggregate ID as a string

func (*Root) SetID

func (ar *Root) SetID(id string) error

SetID opens up the possibility to set manual aggregate ID from the outside

func (*Root) UnsavedEvents

func (ar *Root) UnsavedEvents() bool

UnsavedEvents return true if there's unsaved events on the aggregate

func (*Root) Version

func (ar *Root) Version() eventsourcing.Version

Version return the version based on events that are not stored

type SnapshotMarshal

type SnapshotMarshal func(v interface{}) ([]byte, error)

type SnapshotUnmarshal

type SnapshotUnmarshal func(data []byte, v interface{}) error

Jump to

Keyboard shortcuts

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