Maestro v0.1.2 Maestro.Store.Adapter behaviour View Source

Defines the minimal API for a well-behaved storage implementation.

Link to this section Summary

Callbacks

If any transactional projections are present, this function is an extension of commit_events that within the same transaction applies all projections to the store as well. Otherwise, this function dispatches to commit_events

Events are validated according to the Event.changeset/1 function. If successful, events are committed transactionally. In the event of a conflict on sequence number, the storage mechanism should indicate that the command could be retried by returning {:error, :retry_command}. The Aggregate’s command lifecycle will see the conflict and update the aggregate’s state before attempting to evaluate the command again. This allows for making stricter evaluation rules for commands. If the events could not be committed for any other reason, the storage mechanism should raise an appropriate exception

Snapshots are committed iff the proposed version is newer than the version already stored. This allows disconnected nodes to optimistically write their snapshots and still have a single version stored without conflicts

Events are retrieved by aggregate_id and with at least a minimum sequence number, seq. They should be ordered by sequence number to ensure that aggregates always process events in the same order

Snapshots can also be retrieved by aggregate_id and with at least a minimum sequence number, seq

Link to this section Types

Link to this section Callbacks

Link to this callback commit_all(list, list) View Source
commit_all([Maestro.Types.Event.t()], [module()]) ::
  :ok | {:error, :retry_command}

If any transactional projections are present, this function is an extension of commit_events that within the same transaction applies all projections to the store as well. Otherwise, this function dispatches to commit_events.

Link to this callback commit_events(list) View Source
commit_events([Maestro.Types.Event.t()]) ::
  :ok | {:error, :retry_command} | :no_return

Events are validated according to the Event.changeset/1 function. If successful, events are committed transactionally. In the event of a conflict on sequence number, the storage mechanism should indicate that the command could be retried by returning {:error, :retry_command}. The Aggregate’s command lifecycle will see the conflict and update the aggregate’s state before attempting to evaluate the command again. This allows for making stricter evaluation rules for commands. If the events could not be committed for any other reason, the storage mechanism should raise an appropriate exception.

Link to this callback commit_snapshot(arg0) View Source
commit_snapshot(Maestro.Types.Snapshot.t()) :: :ok | :no_return

Snapshots are committed iff the proposed version is newer than the version already stored. This allows disconnected nodes to optimistically write their snapshots and still have a single version stored without conflicts.

Link to this callback get_events(id, seq, options) View Source
get_events(id(), seq(), options()) :: [Maestro.Types.Event.t()]

Events are retrieved by aggregate_id and with at least a minimum sequence number, seq. They should be ordered by sequence number to ensure that aggregates always process events in the same order.

Additional option(s):

  • :max_sequence (integer): a hard upper limit on the sequence number. This is useful when attempting to recreate a past state of an aggregate.
Link to this callback get_snapshot(id, seq, options) View Source
get_snapshot(id(), seq(), options()) :: nil | Maestro.Types.Snapshot.t()

Snapshots can also be retrieved by aggregate_id and with at least a minimum sequence number, seq.

Additional option(s):

  • :max_sequence (integer): a hard upper limit on the sequence number. This is useful when attempting to recreate a past state of an aggregate.