Documentation
¶
Index ¶
- Variables
- type AggregateType
- type ApplyEventToAggregate
- type Event
- type EventData
- type EventStore
- func (es *EventStore) AppendEvent(ctx context.Context, aggregateID uuid.UUID, event interface{}) (Event, error)
- func (es *EventStore) EventStream() string
- func (es *EventStore) LoadCurrentState(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}) error
- func (es *EventStore) LoadEvents(ctx context.Context, aggregateID uuid.UUID) ([]Event, error)
- func (es *EventStore) LoadEventsRange(ctx context.Context, aggregateID uuid.UUID, ...) ([]Event, error)
- func (es *EventStore) LoadLatestSnapshot(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}) (Snapshot, error)
- func (es *EventStore) LoadNewestEvents(ctx context.Context, aggregateID uuid.UUID, snapshotVersion int32) ([]Event, error)
- func (es *EventStore) LoadSnapshot(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}, ...) (Snapshot, error)
- func (es *EventStore) MakeSnapshot(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}) error
- func (es *EventStore) StoreSnapshot(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}) error
- type EventTime
- type EventType
- type EventVersion
- type GetSnapshotData
- type LastEventVersion
- type LoadAggregateFromSnapshot
- type LoadEventsRangeParams
- type LoadLatestSnapshotParams
- type LoadNewestEventsParams
- type LoadSnapshotParams
- type Snapshot
- type StoreEventParams
- type StoreSnapshotParams
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoSnapshotFound = errors.New("no snapshot found") ErrNoAggreagateStateFound = errors.New("no aggregate state found") ErrFailedToMakeSnapshot = errors.New("failed to make snapshot: no events found for the given aggregate id") ErrAggregateMustBePointer = errors.New("aggregate must be a pointer") ErrApplyEventToAggregate = errors.New("aggregator must implement the ApplyEventToAggregate interface") ErrLastEventVersion = errors.New("to use this method, aggregate must implement the LatestEventVersion interface") )
Predefined errors
Functions ¶
This section is empty.
Types ¶
type AggregateType ¶
type AggregateType interface { // AggregateType returns the type of the aggregate AggregateType() string }
type ApplyEventToAggregate ¶
type EventData ¶
type EventData interface { // EventData returns the data of the event EventData() []byte }
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
EventStore is the facade for the event store
func NewEventStore ¶
NewEventStore creates a new event store
func (*EventStore) AppendEvent ¶
func (es *EventStore) AppendEvent(ctx context.Context, aggregateID uuid.UUID, event interface{}) (Event, error)
AppendEvents appends events to the event store
func (*EventStore) EventStream ¶
func (es *EventStore) EventStream() string
EventStream returns the event stream name
func (*EventStore) LoadCurrentState ¶
func (es *EventStore) LoadCurrentState(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}) error
LoadCurrentState loads the current state for the given aggregate id. It loads the latest snapshot and all events since the snapshot version. Then it applies all events to the snapshot and returns the state.
func (*EventStore) LoadEvents ¶
LoadEvents loads all events for the given aggregate id
func (*EventStore) LoadEventsRange ¶
func (es *EventStore) LoadEventsRange(ctx context.Context, aggregateID uuid.UUID, fromEventVersion, toEventVersion int32) ([]Event, error)
LoadEventsRange loads events for the given aggregate id and event version range
func (*EventStore) LoadLatestSnapshot ¶
func (es *EventStore) LoadLatestSnapshot(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}) (Snapshot, error)
LoadLatestSnapshot loads the latest snapshot for the given aggregate id and aggregate type
func (*EventStore) LoadNewestEvents ¶
func (es *EventStore) LoadNewestEvents(ctx context.Context, aggregateID uuid.UUID, snapshotVersion int32) ([]Event, error)
LoadNewestEvents loads the newest events for the given aggregate id. Helpful when you have a snapshot and want to load all events since the snapshot.
func (*EventStore) LoadSnapshot ¶
func (es *EventStore) LoadSnapshot(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}, snapshotVersion int32) (Snapshot, error)
LoadSnapshot loads the snapshot for the given aggregate id and snapshot version
func (*EventStore) MakeSnapshot ¶
func (es *EventStore) MakeSnapshot(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}) error
MakeSnapshot makes a snapshot for the given aggregate id. Helpful when you want to load all events since the snapshot and apply them to the aggregator. It loads the latest snapshot and all events since the snapshot version. Then it applies all events to the snapshot and stores the new snapshot.
func (*EventStore) StoreSnapshot ¶
func (es *EventStore) StoreSnapshot(ctx context.Context, aggregateID uuid.UUID, aggregate interface{}) error
StoreSnapshot stores a snapshot for the given aggregator. It stores the snapshot and then initializes the aggregator with the snapshot.
type EventTime ¶
type EventTime interface { // EventTime returns the time of the event EventTime() int64 }
type EventType ¶
type EventType interface { // EventType returns the type of the event EventType() string }
type EventVersion ¶
type EventVersion interface { // EventVersion returns the version of the event EventVersion() int32 }
type GetSnapshotData ¶
type LastEventVersion ¶
type LastEventVersion interface { // LastEventVersion returns the version of the latest event LastEventVersion() int32 }
type LoadEventsRangeParams ¶
type LoadNewestEventsParams ¶
type LoadSnapshotParams ¶
type Snapshot ¶
type Snapshot struct { SnapshotID uuid.UUID `json:"snapshot_id"` AggregateID uuid.UUID `json:"aggregate_id"` AggregateType string `json:"aggregate_type"` SnapshotVersion int32 `json:"snapshot_version"` SnapshotData []byte `json:"snapshot_data"` SnapshotTime int64 `json:"snapshot_time"` LatestEventVersion int32 `json:"latest_event_version"` }