INTRO
KVS module provides user level interface for console commands. It has discovery, data manipulation and retrival features. Under the hood it handles configurable run-time backends for each supported database.
You can change backend by setting application env. This behaves well even under the heavy load.
SETUP
In sys.config you should specify kvs backend and list of modules containing metainfo/0 exported function.
[{kvs, [{dba,store_mnesia},
{schema,[kvs,kvs_stream]}]}].
dir() -> list({'table',atom()}).
Returns actual tables.
ver() -> {'version',string()}.
Returns backend version.
dump() -> ok.
Display database information.
> kvs:dump().
NAME STORAGE TYPE MEMORY (MB) ELEMENTS
id_seq disc_copies 0.00 0
writer disc_copies 0.00 0
emails disc_copies 0.00 0
reader disc_copies 0.00 0
Snapshot taken: {{2018,11,10},{5,2,38}}
ok
SEQ
Sequence table id_seq stores the counter per thing. The couners are global and atomic in each supported database. Sequences are used to generate unique names for records per distributed table. If names in the table are not unique, e.g. then count function may return a different value than the current sequence.
-record(id_seq, { thing = atom(),
id = 0 :: integer() } ).
seq(atom(), integer()) -> integer().
Increments and returns id counter for the particular table.
count(atom()) -> integer().
Returns number of records in table.
BACKEND
Data operations.
put(tuple()) -> ok | {error,any()}.
Storing of data record.
get(atom(),any()) -> {ok,any()} | {error, not_found | duplicated }.
Retrieval of data record.
delete(atom(),any()) -> ok | {error,any()}.
Deletion of data record.
index(atom(),any(),any()) -> list(tuple()).
Search of data record by an indexed field and a given value.
This module may refer to: kvs_fs, kvs_mnesia, kvs_rocks, kvs_st, kvs_stream.