Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

$or support #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

$or support #19

wants to merge 4 commits into from

Conversation

flimzy
Copy link
Member

@flimzy flimzy commented Aug 13, 2017

No description provided.

@codecov-io
Copy link

Codecov Report

Merging #19 into master will decrease coverage by 35.92%.
The diff coverage is 68.96%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #19       +/-   ##
===========================================
- Coverage    87.8%   51.87%   -35.93%     
===========================================
  Files           1        2        +1     
  Lines          82      160       +78     
===========================================
+ Hits           72       83       +11     
- Misses          6       74       +68     
+ Partials        4        3        -1
Impacted Files Coverage Δ
operators.go 100% <100%> (ø)
mango.go 48.32% <65.71%> (-39.49%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6447c9b...7006df3. Read the comment docs.

@flimzy
Copy link
Member Author

flimzy commented Aug 13, 2017

func foo(node) {
if node == array {
for i, value = range node {
node = foo(node)
}
}
if node == object {
for key, value = range node {
if len(node) == 1 and value != object {
// implicit equal
node = { "$and": { "$eq": value }}
}
if len(node) == 1 and value == object and isOperator(value.key) {
node = { key + '.' + value.key: value.value }
}
if !isOperator(key) {
node = { "$and": foo(convertToArray(node)) }
}
}
}
return node
}

{"foo": "bar"} => {"$and":[{"foo": {"$eq": "bar"}}]}
{"foo":"bar", "baz":"qux"} => {"$and":[{"foo": {"$eq": "bar"}}, {"baz":{"$eq":"qux"}}]}

x OR ( y AND z )

$or: [ x,
$and [y,z]]

  • object keys are combination operators, values are arrays, do recursion on arrays
  • convert array to selector, only contain objects which are converted to subselectors
  • if array-object value is array, its a combination, otherwise, it's a field condition

CombinationNode
- Operator ($and, $or, etc)
- Array of Nodes

oper
{"$and":[{"foo": {"$eq": "bar"}}, {"baz":{"$eq":"qux"}}]}

ComparisonNode
- Operator ($eq, $gt, etc)
- Field name
- Value

field oper value
{"foo": {"$eq": "bar"}}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants