evoq_read_model behaviour (evoq v1.12.0)
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}
Summary
Functions
Clear all data from the read model.
Delete a value from the read model.
Get a value from the read model.
Get the current checkpoint position.
List all key-value pairs matching a prefix.
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 get(term(), read_model()) -> {ok, term()} | {error, not_found | term()}.
Get a value from the read model.
-spec get_checkpoint(read_model()) -> non_neg_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 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(non_neg_integer(), read_model()) -> read_model().
Set the checkpoint position.