Skip to content

Commit 1f10e8f

Browse files
João RobertoMiguel Molina
authored andcommitted
Like operator
1 parent 17fd2cc commit 1f10e8f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

operators.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ 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.
66+
// See https://www.postgresql.org/docs/9.6/static/functions-matching.html.
67+
func Like(col SchemaField, value string) Condition {
68+
return func(schema Schema) squirrel.Sqlizer {
69+
return &colOp{col.QualifiedName(schema), "LIKE", value}
70+
}
71+
}
72+
6573
// Or returns the given conditions joined by logical ors.
6674
func Or(conds ...Condition) Condition {
6775
return func(schema Schema) squirrel.Sqlizer {

operators_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (s *OpsSuite) TestOperators() {
4949
{"Gt", Gt(f("age"), 1), 2},
5050
{"Lt", Lt(f("age"), 2), 1},
5151
{"Neq", Neq(f("name"), "Joe"), 2},
52+
{"Like", Like(f("name"), "J%"), 2},
5253
{"GtOrEq", GtOrEq(f("age"), 2), 2},
5354
{"LtOrEq", LtOrEq(f("age"), 3), 3},
5455
{"Not", Not(Eq(f("name"), "Joe")), 2},

0 commit comments

Comments
 (0)