reckon_db_snapshots (reckon_db v3.1.1)
View SourceSnapshots API facade for reckon-db
Provides the public API for snapshot operations: - save: Save aggregate state as a snapshot - load: Load the latest snapshot for a stream - load_at: Load a specific snapshot version - list: List all snapshots for a stream - delete: Delete snapshots for a stream - exists: Check if a snapshot exists
Snapshots are used to optimize event replay by storing aggregate state at specific versions.
Summary
Functions
Delete all snapshots for a stream
Delete a specific snapshot version
Check if any snapshot exists for a stream
Check if a specific snapshot version exists
List all snapshots for a stream
Load the latest snapshot for a stream.
Load a specific snapshot version.
Save a snapshot with default empty metadata
Save a snapshot with metadata
Types
-type snapshot() :: #snapshot{stream_id :: binary(), version :: non_neg_integer(), data :: map() | binary(), metadata :: map(), timestamp :: integer(), anchor_hash :: binary() | undefined, mac :: {KeyId :: non_neg_integer(), MacBytes :: binary()} | undefined}.
-type snapshot_metadata() :: map().
Functions
Delete all snapshots for a stream
-spec delete_at(atom(), binary(), non_neg_integer()) -> ok | {error, term()}.
Delete a specific snapshot version
Check if any snapshot exists for a stream
-spec exists_at(atom(), binary(), non_neg_integer()) -> boolean().
Check if a specific snapshot version exists
List all snapshots for a stream
Load the latest snapshot for a stream.
Returns {ok, Snapshot} if found and integrity-valid. Returns {error, not_found} if no snapshot exists. Returns {error, {integrity_violation, _}} if the store has integrity enabled and the loaded snapshot fails verification. Callers (typically aggregate rebuild) should treat an integrity violation as a directive to fall back to full event replay from the stream's chain_start_version watermark.
-spec load_at(atom(), binary(), non_neg_integer()) -> {ok, snapshot()} | {error, not_found} | {error, term()}.
Load a specific snapshot version.
Same verification semantics as load/2.
-spec save(atom(), binary(), non_neg_integer(), snapshot_data()) -> ok | {error, term()}.
Save a snapshot with default empty metadata
Parameters: StoreId - The store identifier StreamId - The stream this snapshot belongs to Version - The event version this snapshot represents Data - The aggregate state to snapshot
Returns ok on success or {error, Reason} on failure.
-spec save(atom(), binary(), non_neg_integer(), snapshot_data(), snapshot_metadata()) -> ok | {error, term()}.
Save a snapshot with metadata