KVS

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.

  • put/1 — put record using id as a key.
  • get/2 — get record by key from table.
  • delete/1 — delete record from table.
  • index/3 — search records by field and its value.
  • seq/2 — generate new sequence table id.
  • count/1 — counts records in table.
  • dir/0 — table list.

You can change backend by setting application env. This behaves well even under the heavy load.

API

Data operations.

put(tuple()) -> ok | {error,any()}.

Stores the record.

get(atom(),any()) -> {ok,any()} | {error, not_found | duplicated }.

Retrieves the record.

delete(atom(),any()) -> ok | {error,any()}.

Deletes the data record.

index(atom(),any(),any()) -> list(tuple()).

Searches the record by an indexed field and a given value.

SEQ

Sequence table id_seq stores the counter per thing. The counters 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.

SETUP

In sys.config you can specify main kvs backend module as dba parameter and list of modules containing metainfo/0 exported function. For the stream operations you can specify the stream kvs backend module dba_st parameter.

[{kvs, [{dba,store_mnesia}, {dba_st,store_stream}, {schema,[kvs,kvs_stream]}]}].

dir() -> list({'table',atom()}).

Returns actual tables.

This module may refer to: kvs_fs, kvs_mnesia, kvs_rocks, kvs_st, kvs_stream.