diff --git a/operators.go b/operators.go index 902df51..ea878fd 100644 --- a/operators.go +++ b/operators.go @@ -62,7 +62,7 @@ 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 { @@ -70,6 +70,14 @@ func Like(col SchemaField, value string) Condition { } } +// 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 { diff --git a/operators_test.go b/operators_test.go index 2dfa7eb..ab37f4f 100644 --- a/operators_test.go +++ b/operators_test.go @@ -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},