Skip to content

Commit

Permalink
added predicate less_or_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
gopherus committed Aug 2, 2023
1 parent 1bed5f7 commit 313054b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
9 changes: 5 additions & 4 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ var Config = &Registry{
),
Predicates: &PredicateRegistry{
registry: map[string]*predicate.Template{
PredicateEqual: NewEqualPredicate(),
PredicateNotEqual: NewNotEqualPredicate(),
PredicateNotIn: NewNotInPredicate(),
PredicateIn: NewInPredicate(),
PredicateEqual: NewEqualPredicate(),
PredicateNotEqual: NewNotEqualPredicate(),
PredicateNotIn: NewNotInPredicate(),
PredicateIn: NewInPredicate(),
PredicateLessOrEqual: NewLessOrEqualPredicate(),
},
},
}
Expand Down
44 changes: 22 additions & 22 deletions config/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const PredicateEqual = "equal"
const PredicateNotEqual = "not_equal"
const PredicateIn = "in"
const PredicateNotIn = "not_in"
const PredicateLessOrEqual = "less_or_equal"

type (
PredicateRegistry struct {
Expand Down Expand Up @@ -60,33 +61,15 @@ func NewPredicates() *PredicateRegistry {
}

func NewEqualPredicate() *predicate.Template {
return equalityCheckPredicate(PredicateEqual, true)
return binaryPredicate(PredicateEqual, "=")
}

func equalityCheckPredicate(name string, equal bool) *predicate.Template {
var negation string
if !equal {
negation = "!"
}

return &predicate.Template{
Name: name,
Source: " ${Alias}.${ColumnName} " + negation + "= $criteria.AppendBinding($FilterValue)",
Args: []*predicate.NamedArgument{
{
Name: "Alias",
Position: 0,
},
{
Name: "ColumnName",
Position: 1,
},
},
}
func NewLessOrEqualPredicate() *predicate.Template {
return binaryPredicate(PredicateLessOrEqual, "<=")
}

func NewNotEqualPredicate() *predicate.Template {
return equalityCheckPredicate(PredicateNotEqual, false)
return binaryPredicate(PredicateNotEqual, "!=")
}

func NewInPredicate() *predicate.Template {
Expand Down Expand Up @@ -120,3 +103,20 @@ func newInPredicate(name string, equal bool) *predicate.Template {
},
}
}

func binaryPredicate(name, operator string) *predicate.Template {
return &predicate.Template{
Name: name,
Source: " ${Alias}.${ColumnName} " + operator + " $criteria.AppendBinding($FilterValue)",
Args: []*predicate.NamedArgument{
{
Name: "Alias",
Position: 0,
},
{
Name: "ColumnName",
Position: 1,
},
},
}
}

0 comments on commit 313054b

Please sign in to comment.