Chronicle.ReadModels (chronicle v0.0.1)

Copy Markdown View Source

Queries Chronicle read model instances.

Read models are populated by reducers and projections. Use get/3 to fetch the current state of a single read model instance by its key, or all/2 to retrieve all instances.

Usage

{:ok, account} = Chronicle.ReadModels.get(MyApp.ReadModels.Account, "account-1")
{:ok, accounts} = Chronicle.ReadModels.all(MyApp.ReadModels.Account)

With explicit client:

{:ok, account} = Chronicle.ReadModels.get(
  MyApp.ReadModels.Account,
  "account-1",
  client: :bank_chronicle
)

Summary

Functions

Returns all instances of the given read model.

Fetches a read model instance by its key.

Functions

all(model_module, opts \\ [])

@spec all(
  module(),
  keyword()
) :: {:ok, [struct()]} | {:error, term()}

Returns all instances of the given read model.

Options

  • :client — the client name (default: Chronicle.Client)
  • :namespace — overrides the client's default namespace
  • :event_sequence_id — the event sequence to project from (default: "event-log")

get(model_module, key, opts \\ [])

@spec get(module(), String.t(), keyword()) :: {:ok, struct() | nil} | {:error, term()}

Fetches a read model instance by its key.

Options

  • :client — the client name (default: Chronicle.Client)
  • :namespace — overrides the client's default namespace
  • :event_sequence_id — the event sequence to project from (default: "event-log")

Returns {:ok, model_struct} on success, or {:ok, nil} if not found.