Any API usage docs? #22

Open
opened 2014-01-25 14:47:56 +00:00 by maxlapshin · 2 comments
maxlapshin commented 2014-01-25 14:47:56 +00:00 (Migrated from github.com)

Hi. I can't find api docs. Are there any?

How should I write and read data from erlang? Maybe there is some simple usage example?

Hi. I can't find api docs. Are there any? How should I write and read data from erlang? Maybe there is some simple usage example?
marianoguerra commented 2014-01-28 13:42:53 +00:00 (Migrated from github.com)

👍

:+1:
opensam commented 2014-01-31 11:41:44 +00:00 (Migrated from github.com)

Here is my little 'write and read data from erlang' sheet :

{ok, Tree} = hanoidb:open("mydb.hanoidb").
ok = hanoidb:put(Tree, <<"key1">>, <<"val1">>).
ok = hanoidb:put(Tree, <<"key2">>, <<"val2">>).
{ok,<<"val1">>} = hanoidb:get(Tree, <<"key1">>).
{ok,<<"val2">>} = hanoidb:get(Tree, <<"key2">>).
ok = hanoidb:close(Tree).

After put/get, here is delete (before close obviously) :
ok = hanoidb:delete(Tree, <<"BOO">>),
not_found = hanoidb:get(Tree, <<"BOO">>)

There si also key expiry:
ok = hanoidb:put(Tree, <<"foo">>, <<"bar">>, 2), % 2 sec
{ok, <<"bar">>} = hanoidb:get(Tree, <<"foo">>),
ok = timer:sleep(3000), % 3000 ms
not_found = hanoidb:get(Tree, <<"foo">>)

And the powerfull fold(DB, Fun, Acc)
see also fold_range in the source.

Hope it helps
Have fun

Here is my little 'write and read data from erlang' sheet : {ok, Tree} = hanoidb:open("mydb.hanoidb"). ok = hanoidb:put(Tree, <<"key1">>, <<"val1">>). ok = hanoidb:put(Tree, <<"key2">>, <<"val2">>). {ok,<<"val1">>} = hanoidb:get(Tree, <<"key1">>). {ok,<<"val2">>} = hanoidb:get(Tree, <<"key2">>). ok = hanoidb:close(Tree). After put/get, here is delete (before close obviously) : ok = hanoidb:delete(Tree, <<"BOO">>), not_found = hanoidb:get(Tree, <<"BOO">>) There si also key expiry: ok = hanoidb:put(Tree, <<"foo">>, <<"bar">>, 2), % 2 sec {ok, <<"bar">>} = hanoidb:get(Tree, <<"foo">>), ok = timer:sleep(3000), % 3000 ms not_found = hanoidb:get(Tree, <<"foo">>) And the powerfull fold(DB, Fun, Acc) see also fold_range in the source. Hope it helps Have fun
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: greg/hanoidb#22
No description provided.