memory.EventStore¶
An in-memory implementation of EventStore. Suitable for testing and prototyping. Data is lost when the process exits.
Package¶
github.com/terraskye/eventsourcing/memory
Constructor¶
func NewEventStore() *EventStore
store := memory.NewEventStore()
defer store.Close()
Behaviour¶
- Each event is kept encoded by
eventsourcing.EncodeEvent, as the persistent stores keep it, in a per-stream map and a global slice. Every read decodes it again, so each read returns its own copy of the event and metadata. ReadAllandHead(GlobalReader) read the global slice;GlobalPositionis the event's index in it plus one.LoadStreamrequires the stream to exist (StreamExistssemantics).LoadStreamFromwithAny{}orRevisionstarts from the given offset.- Thread-safe via
sync.RWMutex. Closeclears all stored events;Savereturns an error after it.
Automation store¶
func NewAutomationStore() *AutomationStore
AutomationStore implements automation.Store in memory: segment leases, pauses and the fair hand-out across groups, for tests and for an automation that runs in one process. Another process does not see its leases; use the sqlite or postgres AutomationStore when several processes run the automation.
Limitations¶
- No durability — data lost on process exit.
- As on the persistent stores, every event type must be registered (see Event registry);
Saverejects an unregistered type withErrEventNotRegistered. Reads return each event as the registry makes it, a pointer such as*TaskCreated, even for an event saved as a value.