WardrikStore. Adapter behaviour
(wardrik_store v0.1.0-rc.1)
Copy Markdown
Decides where a store keeps its keys: in memory, on disk or in Postgres. Callers use
WardrikStore, not the adapter.
An adapter also has a new/1 that builds the store:
defmodule MyApp.Store do
@behaviour WardrikStore.Adapter
def new(opts), do: WardrikStore.new(__MODULE__, Keyword.fetch!(opts, :name))
# child_spec/1, put/4, lookup/2, delete/3 and keys/2 follow
endEach callback gets that config, and a full path that already holds the store's scopes.
lookup_many/2 and entries/2 are optional. Implement them when reading many keys at once
is cheaper than one at a time, as in a database. Otherwise WardrikStore reads keys one at a
time.
Summary
Callbacks
Returns the child that runs the adapter.
Removes path. Returns :ok if it isn't there. Takes :if_vsn as WardrikStore.delete/3 does.
Returns {path, value, vsn} for every path that starts with prefix.
Returns every path that starts with prefix.
Returns {value, vsn} for path, or nil.
Returns {path, value, vsn} for each of paths. Paths that aren't there are left out.
Writes value under path. Takes :if_vsn as WardrikStore.put/4 does.
Types
@type config() :: term()
The config the adapter's new/1 built. Each callback gets it.
Callbacks
@callback child_spec(config()) :: Supervisor.child_spec()
Returns the child that runs the adapter.
Removes path. Returns :ok if it isn't there. Takes :if_vsn as WardrikStore.delete/3 does.
@callback entries(config(), prefix :: String.t()) :: [ {String.t(), term(), WardrikStore.vsn()} ]
Returns {path, value, vsn} for every path that starts with prefix.
Returns every path that starts with prefix.
@callback lookup(config(), path :: String.t()) :: {term(), WardrikStore.vsn()} | nil
Returns {value, vsn} for path, or nil.
@callback lookup_many(config(), paths :: [String.t()]) :: [ {String.t(), term(), WardrikStore.vsn()} ]
Returns {path, value, vsn} for each of paths. Paths that aren't there are left out.
@callback put(config(), path :: String.t(), value :: term(), keyword()) :: {:ok, WardrikStore.vsn() | nil} | {:error, :conflict | term()}
Writes value under path. Takes :if_vsn as WardrikStore.put/4 does.