Skip to content

Commit

Permalink
Support ID searches for 'in' and 'not_in'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik de Vibe committed Oct 4, 2012
1 parent 7987305 commit 130bc2b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/db_adapters/boss_db_adapter_mongodb.erl
Expand Up @@ -247,8 +247,12 @@ build_conditions1([{Key, Operator, Value}|Rest], Acc) ->
[{Key, Value}]; [{Key, Value}];
{Operator, {{_,_,_},{_,_,_}} = Value} -> {Operator, {{_,_,_},{_,_,_}} = Value} ->
[{Key, {boss_to_mongo_op(Operator), datetime_to_now(Value)}}]; [{Key, {boss_to_mongo_op(Operator), datetime_to_now(Value)}}];
{'in', [H|T]} ->
[{Key, {'$in', lists:map(list_pack_function(Key), [H|T])}}];
{'in', {Min, Max}} -> {'in', {Min, Max}} ->
[{Key, {'$gte', Min}}, {Key, {'$lte', Max}}]; [{Key, {'$gte', Min}}, {Key, {'$lte', Max}}];
{'not_in', [H|T]} ->
[{Key, {'$nin', lists:map(list_pack_function(Key), [H|T])}}];
{'not_in', {Min, Max}} -> {'not_in', {Min, Max}} ->
[{'$or', [{Key, {'$lt', Min}}, {Key, {'$gt', Max}}]}]; [{'$or', [{Key, {'$lt', Min}}, {Key, {'$gt', Max}}]}];
{Operator, Value} -> {Operator, Value} ->
Expand All @@ -257,6 +261,18 @@ build_conditions1([{Key, Operator, Value}|Rest], Acc) ->
% ?LOG("Condition", Condition), % ?LOG("Condition", Condition),
build_conditions1(Rest, lists:append(Condition, Acc)). build_conditions1(Rest, lists:append(Condition, Acc)).


list_pack_function(Key) ->
case is_id_attr(Key) of
true ->
fun(Id) -> pack_id(Id) end;
false ->
fun(Value) when is_list(Value) ->
list_to_binary(Value);
(Value) ->
Value
end
end.

where_clause(Format, Params) -> where_clause(Format, Params) ->
erlang:iolist_to_binary( erlang:iolist_to_binary(
io_lib:format(Format, Params)). io_lib:format(Format, Params)).
Expand Down

0 comments on commit 130bc2b

Please sign in to comment.