Skip to content

Commit

Permalink
Put sumo:find_one/2 function back.
Browse files Browse the repository at this point in the history
General fixes according with PR comments.
  • Loading branch information
cabol committed Sep 7, 2016
1 parent f520f47 commit 3964513
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/adapter_test_helpers/sumo_basic_test_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ find(Config) ->
Module = sumo_config:get_prop_value(Name, module),

[First, Second | _] = sumo:find_all(Name),
First = sumo:fetch(Name, Module:id(First)),
First = sumo:find_one(Name, [{id, Module:id(First)}]),
Second = sumo:fetch(Name, Module:id(Second)),
notfound = sumo:fetch(Name, 0),
ok.
Expand Down
12 changes: 10 additions & 2 deletions src/sumo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
-export([
persist/2,
fetch/2,
find_one/2,
find_all/1, find_all/4,
find_by/2, find_by/4, find_by/5,
delete/2,
Expand Down Expand Up @@ -133,6 +134,14 @@ fetch(DocName, Id) ->
{error, Reason} -> Reason
end.

%% @doc Returns 1 doc that matches the given Conditions.
-spec find_one(schema_name(), conditions()) -> user_doc() | notfound.
find_one(DocName, Conditions) ->
case find_by(DocName, Conditions, 1, 0) of
[] -> notfound;
[First | _] -> First
end.

%% @doc Returns all docs from the given store.
-spec find_all(schema_name()) -> [user_doc()].
find_all(DocName) ->
Expand Down Expand Up @@ -313,5 +322,4 @@ normalize_sort_fields(SortFields) when is_list(SortFields) ->

%% @private
get_docs() ->
{ok, Docs} = application:get_env(sumo_db, docs),
Docs.
application:get_env(sumo_db, docs, []).

0 comments on commit 3964513

Please sign in to comment.