Skip to content

Commit f96a365

Browse files
author
Miguel Molina
authored
Merge pull request #139 from jorbs/master
SIMILAR TO operator
2 parents f4ce059 + 728f46c commit f96a365

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

operators.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,22 @@ func Neq(col SchemaField, value interface{}) Condition {
6262
}
6363
}
6464

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

73+
// SimilarTo returns a condition that will be true when `col` matches the given `value`.
74+
// See https://www.postgresql.org/docs/9.6/static/functions-matching.html.
75+
func SimilarTo(col SchemaField, value string) Condition {
76+
return func(schema Schema) squirrel.Sqlizer {
77+
return &colOp{col.QualifiedName(schema), "SIMILAR TO", value}
78+
}
79+
}
80+
7381
// Or returns the given conditions joined by logical ors.
7482
func Or(conds ...Condition) Condition {
7583
return func(schema Schema) squirrel.Sqlizer {

operators_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (s *OpsSuite) TestOperators() {
5050
{"Lt", Lt(f("age"), 2), 1},
5151
{"Neq", Neq(f("name"), "Joe"), 2},
5252
{"Like", Like(f("name"), "J%"), 2},
53+
{"Similar", SimilarTo(f("name"), "An{2}a"), 1},
5354
{"GtOrEq", GtOrEq(f("age"), 2), 2},
5455
{"LtOrEq", LtOrEq(f("age"), 3), 3},
5556
{"Not", Not(Eq(f("name"), "Joe")), 2},

0 commit comments

Comments
 (0)