Started on the local mongo querier

This commit is contained in:
Ruben Vereecken 2014-05-13 21:09:54 +02:00
parent 2f5090df8f
commit 99927d1345
6 changed files with 29 additions and 0 deletions

29
app/lib/LocalMongo.coffee Normal file
View file

@ -0,0 +1,29 @@
LocalMongo = module.exports
LocalMongo.doQuerySelector = (value, operatorObj) ->
for operator, body of operatorObj
switch operator
when '$gt' then return false unless value > body
when '$gte' then return false unless value >= body
when '$in' then return false unless value in body
when '$lt' then return false unless value < body
when '$lte' then return false unless value <= body
when '$ne' then return false unless value != body
when '$nin' then return false if value in body
true
LocalMongo.doLogicalOperator = (target, operatorObj) ->
for operator, body of operatorObj
switch operator
when '$or' then return false unless _.reduce body (res, query) -> res or matchesQuery target x
when '$and' then return false unless _.reduce body (res, query) -> res and matchesQuery target query
#when '$not' then return false if
LocalMongo.matchesQuery = (target, query) ->
for key, value of query
return false unless key in target
if typeof value != 'object'
return false unless target[key] == value
else return false unless doQuerySelector value query[key]

View file

View file