Skip to content

Commit

Permalink
Use the name 'store' instead of 'database'.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Mar 20, 2024
1 parent dedcd04 commit 121865b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

## Overview [↟](#contents)

The ets-kv project (originally "memdb") offers BEAM languages a simple K/V store built on top of [ETS](http://www.erlang.org/doc/man/ets.html). In addition to ETS features and capabilities, ets-kv provides concurrent access to the store using [MVCC](https://en.wikipedia.org/wiki/Multiversion_concurrency_control), allowing multiple clients to read the store concurrently, getting a consitent view of the database without locking.
The ets-kv project (originally "memdb") offers BEAM languages a simple K/V store built on top of [ETS](http://www.erlang.org/doc/man/ets.html). In addition to ETS features and capabilities, ets-kv provides concurrent access to the store using [MVCC](https://en.wikipedia.org/wiki/Multiversion_concurrency_control), allowing multiple clients to read the store concurrently, getting a consitent view of the store without locking.

All writes are serialized for now.

Note that ets-kv's memory consumption increases monotonically, even if keys are deleted or values are updated. Compaction can be
triggered manually or automatically using the auto-vacuum. A full snapshot can be stored or copied in another database
triggered manually or automatically using the auto-vacuum. A full snapshot can be stored or copied in another store
if needed.

## Build [↟](#contents)
Expand All @@ -40,43 +40,43 @@ Start up an Erlang shell:
$ rebar3 shell
```

### Create a database [↟](#contents)
### Create a Store [↟](#contents)

```erl
Name = mydb.
Db = etskv:open(Name).
Name = mystor.
Store = etskv:open(Name).
```

### Store a values [↟](#contents)
### Add a value [↟](#contents)

Storing a value associated to a key using `etskv:put/3`:
Add a value associated with a key using `etskv:put/3`:

```erl
Key = <<"a">>,
Value = 1,
ok = etskv:put(Key, Value, Db).
ok = etskv:put(Key, Value, Store).
```

### Retrieve a value [&#x219F;](#contents)

Use the `etskv:get/2` function to retrieve a value.

```erl
Value = etskv:get(Key, Db).
Value = etskv:get(Key, Store).
```

Value should be `1`. Note that you can use `etskv:contains/2` to check ahead of time:

``` erl
etskv:contains(Key, Db).
etskv:contains(Key, Store).
```

### Delete a value [&#x219F;](#contents)

Use `etskv:delete/2` to delete a value:

```erl
ok = etskv:delete(Key, Db).
ok = etskv:delete(Key, Store).
```

### Working with Multiple Values [&#x219F;](#contents)
Expand All @@ -89,23 +89,23 @@ pass:
```erl
ok = etskv:write_batch([{put, <<"a">>, 1},
{put, <<"b">>, 2},
{put, <<"c">>, 3}], Db),
{put, <<"c">>, 3}], Store),

ok = etskv:write_batch([{put, <<"d">>, 4},
{delete, <<"b">>},
{put, <<"e">>, 5}], Db).
{put, <<"e">>, 5}], Store).
```

#### Retrieving

Use `etskv:fold/4` to retrieve multiples K/Vs

### Close Db [&#x219F;](#contents)
### Close the Store [&#x219F;](#contents)

Close a storage using `etskv:close/1`:

```erl
etskv:close(Db)
etskv:close(Store)
```

## License [&#x219F;](#contents)
Expand Down
12 changes: 6 additions & 6 deletions src/etskv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ put(Key, Value, Db) ->
delete(Key, Db) ->
write_batch([{delete, Key}], Db).

%% @doc Apply atomically a set of updates to the database
%% @doc Apply atomically a set of updates to the store
-spec write_batch(Ops :: write_ops(), Db :: db()) -> ok.
write_batch(Ops, #{ writer := W }) ->
gen_server:call(W, {write, Ops}).

%% @doc check if a Key exists in the database
%% @doc check if a Key exists in the store
-spec contains(Key :: key(), Db :: db()) -> truefalse.
contains(Key, #{ tab := Tab }) ->
case ets:next(Tab, {r, prefix(Key)}) of
Expand All @@ -123,7 +123,7 @@ fold_keys(Fun, Acc0, Db, Opts0) ->
Opts = fold_options(Opts0, ?DEFAULT_FOLD_OPTIONS),
do_fold(Itr, Fun, Acc0, Opts).

%% @doc fold all K/Vs in the database with a function Fun.
%% @doc fold all K/Vs in the store with a function Fun.
%% Additionnaly you can pass the following options:
%% <ul>
%% <li>'gt', (greater than), 'gte' (greather than or equal): define the lower
Expand All @@ -148,7 +148,7 @@ fold(Fun, Acc0, Db, Opts0) ->



%% @doc initialize an iterator. And itterator allows you to iterrate over a consistent view of the database without
%% @doc initialize an iterator. And itterator allows you to iterrate over a consistent view of the store without
%% blocking any writes.
%%
%% Note: compared to ETS you won't have to worry about the possibility that a key may be inserted while you iterrate.
Expand Down Expand Up @@ -208,7 +208,7 @@ iterator_close(Itr) ->
error(timeout)
end.

%% @doc open the database Name
%% @doc open the store Name
-spec open(atom()) -> db().
open(Name) ->
open(Name, []).
Expand All @@ -219,7 +219,7 @@ open(Name, Options) when is_atom(Name) ->
open(Name, _) ->
error({invalid_name, Name}).

%% @doc close a database
%% @doc close the store
close(#{ writer := Writer }) ->
try
gen_server:call(Writer, close, infinity)
Expand Down

0 comments on commit 121865b

Please sign in to comment.