Idiomatic Elixir interface for Chronicle read models.
Read models are the query side of Chronicle. They are produced by projections and reducers and can be queried in two complementary ways:
get/3,get_instance_by_id/3,all/2, andget_instances/2replay the configured event sequence in the same style as the C# and TypeScriptIReadModelsAPIs.query/2queries the materialized read-model container directly for paging and occurrence-oriented inspection.
The module also exposes helper queries for metadata and history:
snapshots/3/get_snapshots_by_id/3occurrences/2/get_occurrences/2definitions/1/get_definitions/1
Common options
Most functions accept these options:
:client— the client name (default:Chronicle.Client):namespace— overrides the client's configured namespace:event_sequence_id— event sequence identifier (default:"event-log")
Single instance lookup
{:ok, account} = Chronicle.ReadModels.get(MyApp.ReadModels.Account, "account-1")
{:ok, account} = Chronicle.ReadModels.get_instance_by_id(MyApp.ReadModels.Account, "account-1")Use :session_id when reading from a dehydrated or session-specific projection:
{:ok, account} =
Chronicle.ReadModels.get_instance_by_id(
MyApp.ReadModels.Account,
"account-1",
session_id: "session-42"
)Replay all instances
{:ok, accounts} = Chronicle.ReadModels.all(MyApp.ReadModels.Account)
{:ok, accounts} = Chronicle.ReadModels.get_instances(MyApp.ReadModels.Account, event_count: 500)Query the materialized container
{:ok, result} = Chronicle.ReadModels.query(MyApp.ReadModels.Account, page: 1, page_size: 25)
result.instances
result.total_countQuery metadata and history
{:ok, snapshots} = Chronicle.ReadModels.snapshots(MyApp.ReadModels.Account, "account-1")
{:ok, occurrences} = Chronicle.ReadModels.occurrences(MyApp.ReadModels.Account)
{:ok, definitions} = Chronicle.ReadModels.definitions()
Summary
Functions
Replays and returns all instances for a read model.
Returns the registered read-model definitions for the current event store.
Fetches a read model instance by key.
Returns the registered read-model definitions for the current event store.
Fetches a read model instance by key.
Replays and returns all instances for a read model.
Returns replay occurrences for a read model.
Returns historical snapshots for a read model instance.
Returns replay occurrences for a read model.
Queries the materialized read-model container directly.
Returns historical snapshots for a read model instance.
Functions
Replays and returns all instances for a read model.
This is the short alias for get_instances/2.
Options
:client— the client name (default:Chronicle.Client):namespace— overrides the client's default namespace:event_sequence_id— event sequence identifier (default:"event-log"):event_count— maximum number of events to process (default: unlimited)
@spec definitions(keyword()) :: {:ok, [Chronicle.ReadModels.Definition.t()]} | {:error, term()}
Returns the registered read-model definitions for the current event store.
This is useful for tooling, diagnostics, and documentation scenarios where you want to inspect the schema and owning observer for each read model.
Options
:client— the client name (default:Chronicle.Client)
Fetches a read model instance by key.
This is the short alias for get_instance_by_id/3.
Options
:client— the client name (default:Chronicle.Client):namespace— overrides the client's default namespace:event_sequence_id— event sequence identifier (default:"event-log"):session_id— optional read-model session identifier
Returns {:ok, model_struct} on success, or {:ok, nil} if no instance was found.
@spec get_definitions(keyword()) :: {:ok, [Chronicle.ReadModels.Definition.t()]} | {:error, term()}
Returns the registered read-model definitions for the current event store.
@spec get_instance_by_id(module(), String.t(), keyword()) :: {:ok, struct() | nil} | {:error, term()}
Fetches a read model instance by key.
Mirrors the getInstanceById() naming used by the Chronicle C# and TypeScript
clients while returning idiomatic Elixir tuples.
Replays and returns all instances for a read model.
This matches the Chronicle getInstances() naming used in the C# and
TypeScript clients.
@spec get_occurrences( module(), keyword() ) :: {:ok, [Chronicle.ReadModels.Occurrence.t()]} | {:error, term()}
Returns replay occurrences for a read model.
@spec get_snapshots_by_id(module(), String.t(), keyword()) :: {:ok, [Chronicle.ReadModels.Snapshot.t()]} | {:error, term()}
Returns historical snapshots for a read model instance.
This mirrors the getSnapshotsById() naming from the Chronicle C# and
TypeScript clients.
@spec occurrences( module(), keyword() ) :: {:ok, [Chronicle.ReadModels.Occurrence.t()]} | {:error, term()}
Returns replay occurrences for a read model.
Occurrences represent replayed or rebuilt versions of a read model and are useful when inspecting rebuilds or alternative containers.
Options
:client— the client name (default:Chronicle.Client):namespace— overrides the client's default namespace
@spec query( module(), keyword() ) :: {:ok, Chronicle.ReadModels.QueryResult.t()} | {:error, term()}
Queries the materialized read-model container directly.
This complements the replay-oriented all/2 and get_instances/2 helpers.
Use it when you need paging or want to inspect a specific replay occurrence.
Options
:client— the client name (default:Chronicle.Client):namespace— overrides the client's default namespace:occurrence— optional occurrence/container name for a replayed read model:page— page number (default:1):page_size— page size (default:50)
@spec snapshots(module(), String.t(), keyword()) :: {:ok, [Chronicle.ReadModels.Snapshot.t()]} | {:error, term()}
Returns historical snapshots for a read model instance.
Snapshots group the projected state together with the event batch that caused it, making this useful for troubleshooting projections and reducers.
Options
:client— the client name (default:Chronicle.Client):namespace— overrides the client's default namespace:event_sequence_id— event sequence identifier (default:"event-log")