AshCommanded.Commanded.SnapshotAdapter (AshCommanded v0.1.0)

View Source

Adapter to integrate AshCommanded's snapshot functionality with Commanded.

This module implements the necessary callbacks to allow Commanded to use AshCommanded's snapshot functionality during aggregate initialization and event application.

It implements the Commanded.Aggregates.Aggregate.Snapshotter behaviour to integrate with Commanded's built-in snapshot support when it's available. During tests without Commanded, it falls back to simpler implementation.

Summary

Functions

Loads a snapshot for an aggregate.

Returns the snapshot threshold for an aggregate module.

Returns the snapshot schema version for an aggregate module.

Takes a snapshot of an aggregate's state.

Functions

load_snapshot(aggregate_module, aggregate_uuid)

Loads a snapshot for an aggregate.

Parameters

  • aggregate_module - The aggregate module
  • aggregate_uuid - The unique identifier of the aggregate

Returns

  • {:ok, version, state} - If a snapshot was found
  • {:error, reason} - If no snapshot was found or could not be loaded

snapshot_threshold(aggregate_module)

Returns the snapshot threshold for an aggregate module.

Parameters

  • aggregate_module - The aggregate module

Returns

The number of events to process before taking a snapshot, or nil if snapshotting is disabled

snapshot_version(aggregate_module)

Returns the snapshot schema version for an aggregate module.

Parameters

  • aggregate_module - The aggregate module

Returns

The snapshot schema version

take_snapshot(aggregate_module, aggregate_state)

Takes a snapshot of an aggregate's state.

Parameters

  • aggregate_module - The aggregate module
  • aggregate_state - The current state of the aggregate

Returns

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