Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Internal doc restructure #471

Merged
merged 14 commits into from
Jun 27, 2022
Merged
31 changes: 0 additions & 31 deletions connor/and_test.go

This file was deleted.

4 changes: 3 additions & 1 deletion connor/connor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package connor
import (
"fmt"
"strings"

"github.com/sourcenetwork/defradb/core"
)

// Match is the default method used in Connor to match some data to a
// set of conditions.
func Match(conditions, data map[string]interface{}) (bool, error) {
func Match(conditions map[FilterKey]interface{}, data core.Doc) (bool, error) {
return MatchWith("$eq", conditions, data)
}

Expand Down
42 changes: 0 additions & 42 deletions connor/connor_test.go

This file was deleted.

59 changes: 0 additions & 59 deletions connor/contains_test.go

This file was deleted.

30 changes: 10 additions & 20 deletions connor/eq.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package connor

import (
"reflect"
"strings"

"github.com/sourcenetwork/defradb/connor/fields"
"github.com/sourcenetwork/defradb/connor/numbers"
"github.com/sourcenetwork/defradb/core"
)

func init() {
Expand Down Expand Up @@ -34,7 +33,8 @@ func (o *EqualOperator) Evaluate(condition, data interface{}) (bool, error) {
return true, nil
}
}
case []map[string]interface{}:
return false, nil
case []core.Doc:
for _, item := range arr {
m, err := MatchWith("$eq", condition, item)
if err != nil {
Expand All @@ -45,6 +45,7 @@ func (o *EqualOperator) Evaluate(condition, data interface{}) (bool, error) {
return true, nil
}
}
return false, nil
}

switch cn := condition.(type) {
Expand All @@ -65,31 +66,20 @@ func (o *EqualOperator) Evaluate(condition, data interface{}) (bool, error) {
return numbers.Equal(cn, data), nil
case float64:
return numbers.Equal(cn, data), nil
case map[string]interface{}:
case map[FilterKey]interface{}:
m := true
for prop, cond := range cn {
if !m {
// No need to evaluate after we fail
continue
}

if strings.HasPrefix(prop, "$") {
mm, err := MatchWith(prop, cond, data)
if err != nil {
return false, err
}

m = m && mm
} else if d, ok := data.(map[string]interface{}); ok {
mm, err := MatchWith("$eq", cond, fields.TryGet(d, prop))
if err != nil {
return false, err
}

m = m && mm
} else {
return reflect.DeepEqual(condition, data), nil
mm, err := MatchWith(prop.GetOperatorOrDefault("$eq"), cond, prop.GetProp(data))
if err != nil {
return false, err
}

m = m && mm
}

return m, nil
Expand Down
Loading