Orchid.Repo behaviour (Orchid v0.6.1)

Copy Markdown View Source

Behaviour for pluggable key-value storage adapters.

Provides the minimal contract shared by every store used in the Orchid ecosystem: write a value, read it back. Domain-specific extensions (existence checks, deletion, garbage collection, bulk export) are defined as separate optional behaviours under Orchid.Repo.*.

Store Reference

Every callback receives an opaque store_ref as its first argument. The concrete type is determined by the adapter (an ETS tid, a map of connection options, a PID, etc.). Callers obtain the reference from the adapter's own init/1 or equivalent.

Composition with Extension Behaviours

Adapters declare the capabilities they support:

defmodule MyApp.BlobStore do
  @behaviour Orchid.Repo
  @behaviour Orchid.Repo.ContentAddressable
  # implements get/2, put/3, exists?/2
end

defmodule MyApp.MetaStore do
  @behaviour Orchid.Repo
  @behaviour Orchid.Repo.Deletable
  @behaviour Orchid.Repo.GC
  # implements get/2, put/3, delete/2, garbage_collect/2
end

Summary

Callbacks

Retrieves the value associated with key.

Persists value under key. Must be idempotent.

Functions

Resolves a {Module, instance} store configuration tuple and dispatches the given function call, prepending the instance as the first argument.

Types

key()

@type key() :: binary()

store_ref()

@type store_ref() :: term()

value()

@type value() :: term()

Callbacks

get(store, key)

@callback get(store :: store_ref(), key()) :: {:ok, value()} | :miss

Retrieves the value associated with key.

Returns {:ok, value} on a hit, or :miss if no entry exists.

put(store, key, value)

@callback put(store :: store_ref(), key(), value()) :: :ok

Persists value under key. Must be idempotent.

Functions

dispatch_store(arg, fun, args)

Resolves a {Module, instance} store configuration tuple and dispatches the given function call, prepending the instance as the first argument.