evoq_read_model behaviour (evoq v1.30.1)
View SourceRead model store behavior for evoq.
Provides an abstract interface for read model storage. Projections use this behavior to persist query-optimized data.
Design Principles
- Read models are optimized for queries (no joins, no calculations) - All calculations happen in projections, not queries - Read models can be rebuilt from events at any time
Callbacks
Required: - init(Config) -> {ok, State} - get(Key, State) -> {ok, Value} | {error, not_found} - put(Key, Value, State) -> {ok, NewState} - delete(Key, State) -> {ok, NewState}
Optional: - list(Prefix, State) -> {ok, [{Key, Value}]} - clear(State) -> {ok, NewState} - durable() -> boolean() Whether the rows survive the projection process and a node restart. A projection pairs a checkpoint store only with a durable read model: a checkpoint that outlives its rows skips the whole history after a restart (evoq #1). Without the callback a read model is not durable.
Summary
Functions
Clear all data from the read model.
Delete a value from the read model.
Whether the read model's rows survive a restart.
Get a value from the read model.
Get the current checkpoint position.
List all key-value pairs matching a prefix.
The module implementing the read model.
Create a new read model instance.
Put a value into the read model.
Set the checkpoint position.
Types
Callbacks
Functions
-spec clear(read_model()) -> {ok, read_model()} | {error, term()}.
Clear all data from the read model.
-spec delete(term(), read_model()) -> {ok, read_model()} | {error, term()}.
Delete a value from the read model.
-spec durable(read_model()) -> boolean().
Whether the read model's rows survive a restart.
A read model is durable only when its module says so with durable/0: assuming it of a module that keeps rows in memory loses them silently, while a durable module that forgot to say so is refused loudly.
-spec get(term(), read_model()) -> {ok, term()} | {error, not_found | term()}.
Get a value from the read model.
-spec get_checkpoint(read_model()) -> integer().
Get the current checkpoint position.
-spec list(term(), read_model()) -> {ok, [{term(), term()}]} | {error, term()}.
List all key-value pairs matching a prefix.
-spec module(read_model()) -> atom().
The module implementing the read model.
-spec new(atom(), map()) -> {ok, read_model()} | {error, term()}.
Create a new read model instance.
-spec put(term(), term(), read_model()) -> {ok, read_model()} | {error, term()}.
Put a value into the read model.
-spec set_checkpoint(integer(), read_model()) -> read_model().
Set the checkpoint position.