Chronik v0.1.2 Chronik.Store.Adapters.Ecto View Source

This is a Ecto adapter for the Store.

The Ecto backend can be configured through environment variables which are resolved by Confex.

The adapter uses two tables:

  • tabAggregates which stores the last snapshot (if any) for a given aggregate_module and id.
  • tabDomainEvents which stores all the domain events. It has a foreing key to tabAggregate to indicate which aggregate emmited the domain event. Events are stored in erlang binary form and also in json for debugging purposes.

Link to this section Summary

Functions

Append a list of events to the Store

This function allows the Projection module to comapre versions of EventRecords coming form the PubSub bus. The implementation depends on the version type but a trivial implementation is to compare the integers and return the corresponding atoms

Retrieves all events from the store starting (but not including) at version

Retrieves all events from the store for a given aggregate starting (but not including) at version

Retrives a snapshot from the Store. If there is no snapshot it returns nil. If there is a snapshot this function should return a tuple {version, state} indicating the state of the snapshot and with wich version of the aggregate was created

This function creates a snapshot in the store for the given aggregate. The Store only stores the last snapshot

Link to this section Functions

Link to this function append(aggregate, events, opts \\ [version: :any]) View Source

Append a list of events to the Store.

aggregate is the agregate that generated the events.

events is an enumberable with the events to append.

options is a keyword indicating the optimistic concurrency checks to perform at the moment of writing to the stream.

Versioning

Possible values are:

  • :any: (default value) no checks are performed, the events are always written

  • :no_stream: verifies that the target stream does not exists yet

  • any other integer value: the event number expected to currently be at

The return values are {:ok, last_inserted_version, records} on success or {:error, message} in case of failure.

Callback implementation for Chronik.Store.append/3.

This function allows the Projection module to comapre versions of EventRecords coming form the PubSub bus. The implementation depends on the version type but a trivial implementation is to compare the integers and return the corresponding atoms.

Callback implementation for Chronik.Store.compare_version/2.

Retrieves all events from the store starting (but not including) at version.

Possible version values are :all (default value) or a term indicating starting read position. Event at version is not included in the result.

The return values are {:ok, version, [event records]} or {:error, message} in case of failure. If no records are found on the stream (starting at version) the function returns {:ok, version, []}.

Callback implementation for Chronik.Store.fetch/1.

Link to this function fetch_by_aggregate(aggregate, version \\ :all) View Source

Retrieves all events from the store for a given aggregate starting (but not including) at version.

Possible version values are :all (default value) or a term indicating starting read position. Event at version is not included in the result.

The return values are {:ok, version, [event records]} or {:error, message} in case of failure. If no records are found on the stream (starting at version) the function returns {:ok, version, []}.

Callback implementation for Chronik.Store.fetch_by_aggregate/2.

Retrives a snapshot from the Store. If there is no snapshot it returns nil. If there is a snapshot this function should return a tuple {version, state} indicating the state of the snapshot and with wich version of the aggregate was created.

Callback implementation for Chronik.Store.get_snapshot/1.

Link to this function snapshot(aggregate, state, version) View Source

This function creates a snapshot in the store for the given aggregate. The Store only stores the last snapshot.

Callback implementation for Chronik.Store.snapshot/3.