EventStore
CQRS Event Store implemented in Elixir. Uses PostgreSQL as the underlying storage. Requires version 9.5 or newer.
License is MIT.
Getting started
EventStore is available in Hex, the package can be installed as follows:
Add eventstore to your list of dependencies in
mix.exs:def deps do
[{:eventstore, "~> 0.0.1"}]end
Ensure eventstore is started before your application:
def application do
[applications: [:eventstore]]end
Add an
eventstoreconfig entry containing the PostgreSQL connection details to each environment's mix config file (e.g.config/dev.exs).
```elixir
config :eventstore, EventStore.Storage,
username: "postgres",
password: "postgres",
database: "eventstore_dev",
hostname: "localhost"
```-
Create the EventStore database using the
mixtask
```
mix event_store.create
```
This will create the database and tables.Sample usage
# start the Storage process
{:ok, store} = EventStore.Storage.start_linkWriting to a Stream
# create a unique identity for the stream
stream_uuid = UUID.uuid4()
# a new stream will be created when the expected version is zero
expected_version = 0
# list of events to persist
events = [
%EventStore.EventData{
headers: %{user: "someuser@example.com"},
payload: %ExampleEvent{key: "value"}
}
]
# append events to stream
{:ok, events} = EventStore.append_to_stream(store, stream_uuid, expected_version, events)Reading Events
# read all events from the stream, starting at the beginning (as from version is 0)
{:ok, recorded_events} = EventStore.read_stream_forward(store, uuid, 0)Benchmark EventStore performance
Run the benchmark suite using mix with the bench environment, as configured in config/bench.exs. Logging is disabled for benchmarking.
MIX_ENV=bench mix do es.reset, app.start, bench