Skip to content

Commit

Permalink
Merge pull request #139 from jorbs/master
Browse files Browse the repository at this point in the history
SIMILAR TO operator
  • Loading branch information
Miguel Molina committed May 3, 2017
2 parents f4ce059 + 728f46c commit f96a365
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion operators.go
Expand Up @@ -62,14 +62,22 @@ func Neq(col SchemaField, value interface{}) Condition {
}
}

// Like returns a condition that will be true when `col` matches the given value.
// Like returns a condition that will be true when `col` matches the given `value`.
// See https://www.postgresql.org/docs/9.6/static/functions-matching.html.
func Like(col SchemaField, value string) Condition {
return func(schema Schema) squirrel.Sqlizer {
return &colOp{col.QualifiedName(schema), "LIKE", value}
}
}

// SimilarTo returns a condition that will be true when `col` matches the given `value`.
// See https://www.postgresql.org/docs/9.6/static/functions-matching.html.
func SimilarTo(col SchemaField, value string) Condition {
return func(schema Schema) squirrel.Sqlizer {
return &colOp{col.QualifiedName(schema), "SIMILAR TO", value}
}
}

// Or returns the given conditions joined by logical ors.
func Or(conds ...Condition) Condition {
return func(schema Schema) squirrel.Sqlizer {
Expand Down
1 change: 1 addition & 0 deletions operators_test.go
Expand Up @@ -50,6 +50,7 @@ func (s *OpsSuite) TestOperators() {
{"Lt", Lt(f("age"), 2), 1},
{"Neq", Neq(f("name"), "Joe"), 2},
{"Like", Like(f("name"), "J%"), 2},
{"Similar", SimilarTo(f("name"), "An{2}a"), 1},
{"GtOrEq", GtOrEq(f("age"), 2), 2},
{"LtOrEq", LtOrEq(f("age"), 3), 3},
{"Not", Not(Eq(f("name"), "Joe")), 2},
Expand Down

0 comments on commit f96a365

Please sign in to comment.