KV (Vik v0.0.1-rc1)
View SourceA modular key-value store for arbitrary,
disk-persisted term storage based on :dets
.
Usage
Add KV
to your supervision tree:
{KV, root: "/tmp"}
Summary
Functions
Returns a specification to start this module under a supervisor.
Deletes all objects from the given table
, effectively
emptying it.
Deletes the object for the given key
from table
.
Gets the object for the given key
from table
.
Same as fetch/2
, but returns nil
if the given table
or key cannot be found.
Lists all objects in the given table
.
Puts the given object
in table
.
Starts the store.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec clear(table()) :: :ok | :error
Deletes all objects from the given table
, effectively
emptying it.
Examples
iex> KV.list(:users)
[%User{id: 1, name: "Robin", age: 18}, %User{id: 2, name: "Gijs", age: 15}]
iex> KV.clear(:users)
iex> KV.list(:users)
[]
Deletes the object for the given key
from table
.
Examples
iex> KV.put(:users, 1, %User{id: 1, name: "Robin", age: 18})
iex> KV.get(:users, 1)
%User{id: 1, name: "Robin", age: 18}
iex> KV.delete(:users, 1)
iex> KV.get(:users, 1)
nil
Gets the object for the given key
from table
.
Examples
iex> KV.get(:users, 1)
{:ok, %User{id: 1, name: "Robin", age: 18}}
iex> KV.get(:users, 3)
:error
iex> KV.get(:non_existant, 3)
:error
Same as fetch/2
, but returns nil
if the given table
or key cannot be found.
Examples
iex> KV.get(:users, 1)
%User{id: 1, name: "Robin", age: 18}
iex> KV.get(:users, 3)
nil
iex> KV.get(:non_existant, 3)
nil
Lists all objects in the given table
.
Examples
iex> KV.list(:users)
[%User{id: 1, name: "Robin", age: 18}, %User{id: 2, name: "Gijs", age: 15}]
Puts the given object
in table
.
If the table does not exist yet, it is created on-demand.
Examples
iex> KV.put(:users, 1, %User{id: 1, name: "Robin", age: 18})
iex> KV.put(:users, 2, %User{id: 2, name: "Gijs", age: 15})
:ok
@spec start_link(start_opts()) :: :ok
Starts the store.