Skip to content

Commit

Permalink
Support del and delete; del is now preferred.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Mar 20, 2024
1 parent 80ebea3 commit 5a02320
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ ok = etskv:batch([{put, <<"a">>, 1},
{put, <<"c">>, 3}], Store),

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

Expand Down
6 changes: 4 additions & 2 deletions src/etskv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

-type key() :: binary().
-type value() :: term() | any().
-type batch_ops() :: [{put, key(), value()} | {delete, key()}].
-type batch_ops() :: [{put, key(), value()} | {delete, key()} | {del, key()}].
-type fold_options() :: [{start_key, key()}
| {end_key, key()}
| {gt, key()}
Expand Down Expand Up @@ -101,7 +101,7 @@ put(Key, Value, Db) ->
%% @doc delete a Key
-spec delete(Key :: key(), Db :: db()) -> ok.
delete(Key, Db) ->
batch([{delete, Key}], Db).
batch([{del, Key}], Db).

%% @doc Apply atomically a set of updates to the store
-spec batch(Ops :: batch_ops(), Db :: db()) -> ok.
Expand Down Expand Up @@ -436,6 +436,8 @@ process_ops([{put, Key, Value} | Rest], Version, Tab, Acc) ->
{{k, Key}, Meta}| Acc],
process_ops(Rest, Version, Tab, Acc2);
process_ops([{delete, Key} | Rest], Version, Tab, Acc) ->
process_ops([{del, Key} | Rest], Version, Tab, Acc);
process_ops([{del, Key} | Rest], Version, Tab, Acc) ->
case ets:lookup(Tab, {k, Key}) of
[] ->
process_ops(Rest, Version, Tab, Acc);
Expand Down

0 comments on commit 5a02320

Please sign in to comment.