Jido.Thread.Store behaviour (Jido v2.3.1)

Copy Markdown View Source

Persistence behavior for Thread storage.

Store operations return updated store state to preserve purity for adapters that don't use external processes.

Example

{:ok, store} = Thread.Store.new()

thread = Thread.new(id: "t1")
{:ok, store} = Thread.Store.save(store, thread)

{:ok, store, loaded} = Thread.Store.load(store, "t1")

Summary

Callbacks

Append entries to thread

Initialize adapter state

Load thread by ID

Functions

Append entries to thread in store

Delete thread from store

List all thread IDs in store

Load thread from store

Save thread to store

Types

adapter_state()

@type adapter_state() :: term()

t()

@type t() :: %Jido.Thread.Store{adapter: module(), adapter_state: adapter_state()}

Callbacks

append(adapter_state, thread_id, list)

@callback append(adapter_state(), thread_id :: String.t(), [Jido.Thread.Entry.t()]) ::
  {:ok, adapter_state(), Jido.Thread.t()} | {:error, adapter_state(), term()}

Append entries to thread

init(opts)

@callback init(opts :: keyword()) :: {:ok, adapter_state()} | {:error, term()}

Initialize adapter state

load(adapter_state, thread_id)

@callback load(adapter_state(), thread_id :: String.t()) ::
  {:ok, adapter_state(), Jido.Thread.t()}
  | {:error, adapter_state(), :not_found | term()}

Load thread by ID

save(adapter_state, t)

@callback save(adapter_state(), Jido.Thread.t()) ::
  {:ok, adapter_state()} | {:error, adapter_state(), term()}

Save thread

Functions

append(store, thread_id, entries)

@spec append(t(), String.t(), Jido.Thread.Entry.t() | [Jido.Thread.Entry.t()]) ::
  {:ok, t(), Jido.Thread.t()} | {:error, t(), term()}

Append entries to thread in store

delete(store, thread_id)

@spec delete(t(), String.t()) :: {:ok, t()} | {:error, t(), term()}

Delete thread from store

list(store)

@spec list(t()) :: {:ok, t(), [String.t()]} | {:error, t(), term()}

List all thread IDs in store

load(store, thread_id)

@spec load(t(), String.t()) :: {:ok, t(), Jido.Thread.t()} | {:error, t(), term()}

Load thread from store

new(adapter \\ __MODULE__.Adapters.InMemory, opts \\ [])

@spec new(
  module(),
  keyword()
) :: {:ok, t()} | {:error, term()}

Create new store with adapter

save(store, thread)

@spec save(t(), Jido.Thread.t()) :: {:ok, t()} | {:error, t(), term()}

Save thread to store