Skip to content

Commit

Permalink
Add holds and notHolds operators
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-obernberger committed Jun 2, 2022
1 parent bb68beb commit 9e16d87
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
signStartsWith = "startsWith"
signIn = "in"
signNotIn = "notIn"
signHolds = "holds"
signNotHolds = "notHolds"

signLenEq = "leneq"
signLenNotEq = "lenneq"
Expand Down Expand Up @@ -192,6 +194,16 @@ func notIn(x, y interface{}) (bool, error) {
return !b, err
}

// holds checks if x contains y e.g: holds("[1,2,3]", 1)
func holds(x, y interface{}) (bool, error) {
return in(y, x)
}

// notHolds checks if x doesn't contain y e.g: notHolds("[1,2,3]", 1)
func notHolds(x, y interface{}) (bool, error) {
return notIn(y, x)
}

// lenEq checks if the string/array/list value is equal
func lenEq(x, y interface{}) (bool, error) {
yv, ok := y.(int)
Expand Down Expand Up @@ -307,6 +319,9 @@ func loadDefaultQueryMap() map[string]QueryFunc {
queryMap[signIn] = in
queryMap[signNotIn] = notIn

queryMap[signHolds] = holds
queryMap[signNotHolds] = notHolds

queryMap[signLenEq] = lenEq
queryMap[signLenNotEq] = lenNotEq

Expand Down

0 comments on commit 9e16d87

Please sign in to comment.