# `WardrikStore.Adapter`

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
    end

Each callback gets that config, and a full path that already holds the store's scopes.

`c:lookup_many/2` and `c: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.

# `config`

```elixir
@type config() :: term()
```

The config the adapter's `new/1` built. Each callback gets it.

# `child_spec`

```elixir
@callback child_spec(config()) :: Supervisor.child_spec()
```

Returns the child that runs the adapter.

# `delete`

```elixir
@callback delete(config(), path :: String.t(), keyword()) ::
  :ok | {:error, :conflict | term()}
```

Removes `path`. Returns `:ok` if it isn't there. Takes `:if_vsn` as `WardrikStore.delete/3` does.

# `entries`
*optional* 

```elixir
@callback entries(config(), prefix :: String.t()) :: [
  {String.t(), term(), WardrikStore.vsn()}
]
```

Returns `{path, value, vsn}` for every path that starts with `prefix`.

# `keys`

```elixir
@callback keys(config(), prefix :: String.t()) :: [String.t()]
```

Returns every path that starts with `prefix`.

# `lookup`

```elixir
@callback lookup(config(), path :: String.t()) :: {term(), WardrikStore.vsn()} | nil
```

Returns `{value, vsn}` for `path`, or `nil`.

# `lookup_many`
*optional* 

```elixir
@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.

# `put`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
