WardrikStore (wardrik_store v0.1.0-rc.1)
Copy MarkdownA durable key-value store. Wardrik packages keep their data in it, each under its own scope.
store = WardrikStore.ETS.new(name: MyApp.Store)
children = [{WardrikStore, store}]
vault = WardrikStore.scope(store, "wardrik_vault")
{:ok, vsn} = WardrikStore.put(vault, "github/jon", grant, if_vsn: nil)An adapter decides where the keys are kept. See WardrikStore.ETS, WardrikStore.EKV and
WardrikStore.Ecto.
Summary
Functions
Returns the child spec that runs the store.
Removes key. Returns :ok, also when key isn't there.
Returns {key, value, vsn} for each of the scope's keys that starts with prefix, sorted by key.
Returns the value under key, or nil.
Returns the scope's keys that start with prefix, sorted.
Returns {value, vsn} for key, or nil.
Returns %{key => {value, vsn}} for keys. Keys that aren't there are left out.
Builds a store over adapter. Adapters call this from their own new/1.
Writes value under key. Returns {:ok, vsn}.
Returns the store nested under the scope name.
Types
@type key() :: String.t()
A key within a scope.
@type t() :: %WardrikStore{ adapter: module(), config: WardrikStore.Adapter.config(), scope: String.t() }
A store, scoped or not.
@type vsn() :: term()
The version an adapter stamps a write with.
Functions
@spec child_spec(t()) :: Supervisor.child_spec()
Returns the child spec that runs the store.
Starts nothing if the store is already running. So each thing that uses the store can list it among its own children.
children = [{WardrikStore, store}, {MyApp.Uses, store: store}]
Removes key. Returns :ok, also when key isn't there.
Options
:if_vsn- removes only this version. Returns{:error, :conflict}otherwise.
Returns {key, value, vsn} for each of the scope's keys that starts with prefix, sorted by key.
Returns the value under key, or nil.
Returns the scope's keys that start with prefix, sorted.
Returns {value, vsn} for key, or nil.
Returns %{key => {value, vsn}} for keys. Keys that aren't there are left out.
@spec new(module(), WardrikStore.Adapter.config()) :: t()
Builds a store over adapter. Adapters call this from their own new/1.
@spec put(t(), key(), term(), [{:if_vsn, vsn() | nil}]) :: {:ok, vsn() | nil} | {:error, :conflict | term()}
Writes value under key. Returns {:ok, vsn}.
{:ok, vsn} = WardrikStore.put(store, "settings/theme", "dark", if_vsn: nil)
{:ok, _vsn} = WardrikStore.put(store, "settings/theme", "light", if_vsn: vsn)
{:error, :conflict} = WardrikStore.put(store, "settings/theme", "blue", if_vsn: vsn)Options
:if_vsn- writes only over this version, or only wherekeyis empty whennil. Returns{:error, :conflict}otherwise. Without it, the write always lands, and some adapters return{:ok, nil}.
Returns the store nested under the scope name.
Keys in one scope never match keys in another.
mine = WardrikStore.scope(store, "my_app")name starts with a lowercase letter, followed by lowercase letters, digits and underscores.
Raises ArgumentError otherwise.