summaryrefslogtreecommitdiff
path: root/src/db.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.erl')
-rw-r--r--src/db.erl15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/db.erl b/src/db.erl
index 857615c..3529080 100644
--- a/src/db.erl
+++ b/src/db.erl
@@ -51,8 +51,7 @@ dump_to_file(Filename) ->
mnesia:dump_to_textfile(Filename).
init(_Args) ->
- {mnesia:wait_for_tables([plop], 5000),
- []}.
+ {mnesia:wait_for_tables([plop], 5000), []}.
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
@@ -100,4 +99,14 @@ handle_call({dump, Table}, _From, State) ->
Res = mnesia:transaction(F),
{reply, Res, State};
handle_call({find, Hash}, _From, State) ->
- {reply, mnesia:dirty_read({plop, Hash}), State}.
+ F = fun() ->
+ mnesia:select(plop,
+ [{#plop{hash = Hash, _='_'}, [], ['$_']}])
+ end,
+ {atomic, Result} = mnesia:transaction(F),
+ Record = case length(Result) of
+ 0 -> [];
+ 1 -> hd(Result);
+ _ -> duplicate_hash_in_db % FIXME: log an error
+ end,
+ {reply, Record, State}.