reckon_db_snapshots (reckon_db v1.2.7)

View Source

Snapshots 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

snapshot/0

-type snapshot() ::
          #snapshot{stream_id :: binary(),
                    version :: non_neg_integer(),
                    data :: map() | binary(),
                    metadata :: map(),
                    timestamp :: integer()}.

snapshot_data/0

-type snapshot_data() :: map() | binary().

snapshot_metadata/0

-type snapshot_metadata() :: map().

Functions

delete(StoreId, StreamId)

-spec delete(atom(), binary()) -> ok | {error, term()}.

Delete all snapshots for a stream

delete_at(StoreId, StreamId, Version)

-spec delete_at(atom(), binary(), non_neg_integer()) -> ok | {error, term()}.

Delete a specific snapshot version

exists(StoreId, StreamId)

-spec exists(atom(), binary()) -> boolean().

Check if any snapshot exists for a stream

exists_at(StoreId, StreamId, Version)

-spec exists_at(atom(), binary(), non_neg_integer()) -> boolean().

Check if a specific snapshot version exists

list(StoreId, StreamId)

-spec list(atom(), binary()) -> {ok, [snapshot()]} | {error, term()}.

List all snapshots for a stream

load(StoreId, StreamId)

-spec load(atom(), binary()) -> {ok, snapshot()} | {error, not_found}.

Load the latest snapshot for a stream

Returns {ok, Snapshot} if found, {error, not_found} otherwise.

load_at(StoreId, StreamId, Version)

-spec load_at(atom(), binary(), non_neg_integer()) -> {ok, snapshot()} | {error, not_found}.

Load a specific snapshot version

save(StoreId, StreamId, Version, Data)

-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.

save(StoreId, StreamId, Version, Data, Metadata)

-spec save(atom(), binary(), non_neg_integer(), snapshot_data(), snapshot_metadata()) ->
              ok | {error, term()}.

Save a snapshot with metadata