AshCommanded.Commanded.SnapshotStore behaviour (AshCommanded v0.1.0)

View Source

Defines the behavior and default implementation for aggregate snapshot storage.

The snapshot store is responsible for storing and retrieving snapshots of aggregates, providing a performance optimization by allowing the system to load the latest snapshot rather than replaying all events from the beginning.

The default implementation uses ETS tables for storage. Alternative implementations can be provided by specifying a custom snapshot store module in the application config.

Summary

Callbacks

Deletes all snapshots for an aggregate.

Gets the latest snapshot for an aggregate by its UUID.

Initializes the snapshot store.

Saves a snapshot of an aggregate.

Functions

Deletes all snapshots for an aggregate.

Gets the latest snapshot for an aggregate by its UUID.

Initializes the snapshot store.

Saves a snapshot of an aggregate.

Callbacks

delete_snapshots(t, module)

@callback delete_snapshots(String.t(), module()) :: :ok | {:error, any()}

Deletes all snapshots for an aggregate.

Parameters

  • source_uuid - The unique identifier of the aggregate
  • source_type - The aggregate module

Returns

  • :ok - If the snapshots were deleted successfully
  • {:error, reason} - If the snapshots could not be deleted

get_snapshot(t, module)

@callback get_snapshot(String.t(), module()) ::
  {:ok, AshCommanded.Commanded.Snapshot.t()} | :error

Gets the latest snapshot for an aggregate by its UUID.

Parameters

  • source_uuid - The unique identifier of the aggregate
  • source_type - The aggregate module

Returns

  • {:ok, snapshot} - If a snapshot was found
  • :error - If no snapshot was found

init(any)

@callback init(any()) :: :ok | {:error, any()}

Initializes the snapshot store.

Parameters

  • config - Configuration options for the snapshot store

Returns

  • :ok - If the snapshot store was initialized successfully
  • {:error, reason} - If the snapshot store could not be initialized

save_snapshot(t)

@callback save_snapshot(AshCommanded.Commanded.Snapshot.t()) :: :ok | {:error, any()}

Saves a snapshot of an aggregate.

Parameters

  • snapshot - The snapshot to save

Returns

  • :ok - If the snapshot was saved successfully
  • {:error, reason} - If the snapshot could not be saved

Functions

delete_snapshots(source_uuid, source_type)

@spec delete_snapshots(String.t(), module()) :: :ok | {:error, any()}

Deletes all snapshots for an aggregate.

Parameters

  • source_uuid - The unique identifier of the aggregate
  • source_type - The aggregate module

Returns

  • :ok - If the snapshots were deleted successfully
  • {:error, reason} - If the snapshots could not be deleted

get_snapshot(source_uuid, source_type)

@spec get_snapshot(String.t(), module()) ::
  {:ok, AshCommanded.Commanded.Snapshot.t()} | :error

Gets the latest snapshot for an aggregate by its UUID.

Parameters

  • source_uuid - The unique identifier of the aggregate
  • source_type - The aggregate module

Returns

  • {:ok, snapshot} - If a snapshot was found
  • :error - If no snapshot was found

init(config)

@spec init(any()) :: :ok

Initializes the snapshot store.

Parameters

  • config - Configuration options for the snapshot store (unused for ETS implementation)

Returns

  • :ok - If the snapshot store was initialized successfully

save_snapshot(snapshot)

@spec save_snapshot(AshCommanded.Commanded.Snapshot.t()) :: :ok | {:error, any()}

Saves a snapshot of an aggregate.

Parameters

  • snapshot - The snapshot to save

Returns

  • :ok - If the snapshot was saved successfully
  • {:error, reason} - If the snapshot could not be saved