Skip to content

Read Models

A read model is projected state built from events by an observer. Chronicle maintains read model instances in storage and updates them as new events arrive. Each instance is identified by a key — typically an event source ID — and contains a document that represents the current state of that entity.

Lists all read model definitions registered in the specified event store and namespace.

Terminal window
cratis chronicle read-models list
FlagDescription
-e, --event-store <NAME>Event store to inspect. Defaults to default.
-n, --namespace <NAME>Namespace to inspect. Defaults to Default.

The table includes a Queryable column (Yes/No) indicating whether the read model stores state server-side and can be inspected with get or instances. Client-owned read models show No — their state lives in the client application and cannot be retrieved through the Chronicle server. The JSON output includes a queryable boolean field for programmatic use.

Use --output plain when enumerating read model names. The plain format is approximately 27 times smaller than JSON because it omits the full type metadata included in the JSON output.

Terminal window
cratis chronicle read-models list --output plain

List all read models:

Terminal window
cratis chronicle read-models list

Get read model names for scripting:

Terminal window
cratis chronicle read-models list -q

Lists the stored instances of a read model, with pagination support.

Terminal window
cratis chronicle read-models instances <READ_MODEL>
ArgumentDescription
READ_MODELThe read model name. Use read-models list -q to retrieve names.
FlagDescription
-e, --event-store <NAME>Event store to inspect. Defaults to default.
-n, --namespace <NAME>Namespace to inspect. Defaults to Default.
--page <NUMBER>Zero-based page index. Defaults to 0.
--page-size <COUNT>Number of instances per page. Defaults to 20.

List the first page of instances:

Terminal window
cratis chronicle read-models instances UserProfile

List the second page with a larger page size:

Terminal window
cratis chronicle read-models instances UserProfile --page 1 --page-size 50

Gets a single read model instance by key.

Terminal window
cratis chronicle read-models get <READ_MODEL> <KEY>
ArgumentDescription
READ_MODELThe read model name.
KEYThe instance key, typically an event source ID.
FlagDescription
-e, --event-store <NAME>Event store to inspect. Defaults to default.
-n, --namespace <NAME>Namespace to inspect. Defaults to Default.
--sequence <NAME>Event sequence associated with the read model. Defaults to the event log.

Get a read model instance:

Terminal window
cratis chronicle read-models get UserProfile user-42

Get the full document as JSON:

Terminal window
cratis chronicle read-models get UserProfile user-42 -o json

Gets the number of times a read model type has been stored, optionally for a specific generation.

Terminal window
cratis chronicle read-models occurrences <READ_MODEL_TYPE>
ArgumentDescription
READ_MODEL_TYPEThe read model type name.
FlagDescription
-e, --event-store <NAME>Event store to inspect. Defaults to default.
-n, --namespace <NAME>Namespace to inspect. Defaults to Default.
--generation <NUMBER>Read model generation to count. Defaults to 1.

Count all instances of a read model:

Terminal window
cratis chronicle read-models occurrences UserProfile

Count a specific generation:

Terminal window
cratis chronicle read-models occurrences UserProfile --generation 2

Lists or retrieves snapshots for a specific read model instance. Snapshots are point-in-time captures of a read model’s state, including the sequence number at which the snapshot was taken.

Terminal window
cratis chronicle read-models snapshots <READ_MODEL> <KEY>
ArgumentDescription
READ_MODELThe read model name.
KEYThe instance key, typically an event source ID.
FlagDescription
-e, --event-store <NAME>Event store to inspect. Defaults to default.
-n, --namespace <NAME>Namespace to inspect. Defaults to Default.

List snapshots for an instance:

Terminal window
cratis chronicle read-models snapshots UserProfile user-42

Get snapshot details including full documents and event metadata:

Terminal window
cratis chronicle read-models snapshots UserProfile user-42 -o json