Chronik v0.1.10 Chronik.Store.Adapters.Ecto View Source
Ecto adapter for Chronik.Store
Configuration
You can configure compression for the aggregate snapshot and domain events only for this adapter. By default both values are at 0 (compression disabled).
:aggregate_compression_level
:domain_event_compression_level
Both accept an integer from 0 to 9, being 9 the highest compression.
Link to this section Summary
Functions
Append a list of events to the Store
Returns a specification to start this module under a supervisor
This function allows the Projection module to comapre versions of EventRecords coming form the PubSub bus
Retrives the current version of the store. If there are no record returns :empty
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
Invoked when the server is started. start_link/3
or start/3
will
block until it returns
Remove all events for given aggregate
This function creates a snapshot in the store for the given
aggregate
. The Store only stores the last snapshot
Calls the fun
function over a stream of domain events starting at version
version
Calls the fun
function over the aggregate
’s domain event stream
starting at version version
Link to this section Functions
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 yetany other 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
.
Returns a specification to start this module under a supervisor.
See Supervisor
.
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
.
Retrives the current version of the store. If there are no record returns :empty.
Callback implementation for Chronik.Store.current_version/0
.
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
.
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
.
Invoked when the server is started. start_link/3
or start/3
will
block until it returns.
args
is the argument term (second argument) passed to start_link/3
.
Returning {:ok, state}
will cause start_link/3
to return
{:ok, pid}
and the process to enter its loop.
Returning {:ok, state, timeout}
is similar to {:ok, state}
except handle_info(:timeout, state)
will be called after timeout
milliseconds if no messages are received within the timeout.
Returning {:ok, state, :hibernate}
is similar to
{:ok, state}
except the process is hibernated before entering the loop. See
c:handle_call/3
for more information on hibernation.
Returning :ignore
will cause start_link/3
to return :ignore
and the
process will exit normally without entering the loop or calling c:terminate/2
.
If used when part of a supervision tree the parent supervisor will not fail
to start nor immediately try to restart the GenServer
. The remainder of the
supervision tree will be (re)started and so the GenServer
should not be
required by other processes. It can be started later with
Supervisor.restart_child/2
as the child specification is saved in the parent
supervisor. The main use cases for this are:
- The
GenServer
is disabled by configuration but might be enabled later. - An error occurred and it will be handled by a different mechanism than the
Supervisor
. Likely this approach involves callingSupervisor.restart_child/2
after a delay to attempt a restart.
Returning {:stop, reason}
will cause start_link/3
to return
{:error, reason}
and the process to exit with reason reason
without
entering the loop or calling c:terminate/2
.
Callback implementation for GenServer.init/1
.
Remove all events for given aggregate
Callback implementation for Chronik.Store.remove_events/1
.
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
.
Calls the fun
function over a stream of domain events starting at version
version
.
Callback implementation for Chronik.Store.stream/2
.
Calls the fun
function over the aggregate
’s domain event stream
starting at version version
.
Callback implementation for Chronik.Store.stream_by_aggregate/3
.