# README
Go EventStore
Embeddable EventStore implementation written in Go using gorm as an underlying persistence mechanism meaning it will work
with almost
(tested sqlite and postgres) whatever underlying database gorm will support (just use the respective gorm driver).
Features
- Appending (saving) events to a particular stream
- Reading events from the stream
- Reading all events
- Subscribing (streaming) all events from the event store (real-time)
- Fault-tolerant projection system (Projector)
Upcoming
Add offset handling and retry mechanism to the default Projector.
Example
I provided a simple example that showcases basic usage with sqlite.
# Functions
FlushAfter wraps the projection passed in and it calls the projection itself as new events come (as usual) in addition to calling the provided flush function periodically each time flush interval expires.
New construct new event store dbname - a path to sqlite database on disk enc - a specific encoder implementation (see bundled JsonEncoder).
NewJSONEncoder constructs json encoder It receives a slice of event types it should be able to encode/decode.
NewProjector constructs a Projector TODO Configure logger, pollInterval, and retry.
WithBatchSize is a subscription/read all option that specifies the read batch size (limit) when reading events from the event store.
WithMetaData is an AppendStream option that can be used to associate arbitrary meta data to a batch of events to store.
WithOffset is a subscription / read all option that indicates an offset in the event store from which to start reading events (exclusive).
WithPollInterval is a subscription/read all option that specifies the poolling interval of the underlying sqlite database.
# Constants
InitialStreamVersion can be used as an initial expectedVer for new streams (as an argument to AppendStream).
# Variables
ErrConcurrencyCheckFailed indicates that stream entry related to a particular version already exists.
ErrStreamNotFound indicates that the requested stream does not exist in the event store.
ErrSubscriptionClosedByClient is produced by sub.Err if client cancels the subscription using sub.Close().
# Structs
AggregateRoot represents reusable DDD Event Sourcing friendly Aggregate base type which provides helpers for easy aggregate initialization and event handler execution.
AppendStreamConfig (configure using AppendStreamOpt).
EncodedEvt represents encoded event used by a specific encoder implementation.
EventData holds stored event data and meta data.
EventStore represents a sqlite event store implementation.
JsonEncoder provides default json Encoder implementation It will marshal and unmarshal events to/from json and store the type name.
Projector is an event projector which will subscribe to an event stream (evet store) and project events to each individual projection in an asynchronous manner.
SubAllConfig (configure using SubAllOpt).
Subscription represents ReadAll subscription that is used for streaming incoming events.
# Interfaces
Encoder is used by the event store in order to correctly marshal and unmarshal event types.
EventStreamer represents an event stream that can be subscribed to This package offers EventStore as EventStreamer implementation.
# Type aliases
AppendStreamOpt represents append to stream option.
Projection represents a projection that should be able to handle projected events.
SubAllOpt represents subscribe to all events option.