Skip to content

Commit e6de572

Browse files
authored
Merge pull request #168 from vallahaye/167-add-logical-not-and-not-ilike-comparison-operators
Add logical NOT and NOT ILIKE operators
2 parents d6f429c + fc176ca commit e6de572

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cond.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ func (c *Cond) NotLike(field string, value interface{}) string {
188188
return buf.String()
189189
}
190190

191+
// NotILike represents "field NOT ILIKE value".
192+
func (c *Cond) NotILike(field string, value interface{}) string {
193+
buf := newStringBuilder()
194+
buf.WriteString(Escape(field))
195+
buf.WriteString(" NOT ILIKE ")
196+
buf.WriteString(c.Args.Add(value))
197+
return buf.String()
198+
}
199+
191200
// IsNull represents "field IS NULL".
192201
func (c *Cond) IsNull(field string) string {
193202
buf := newStringBuilder()
@@ -244,6 +253,14 @@ func (c *Cond) And(andExpr ...string) string {
244253
return buf.String()
245254
}
246255

256+
// Not represents "NOT expr".
257+
func (c *Cond) Not(notExpr string) string {
258+
buf := newStringBuilder()
259+
buf.WriteString("NOT ")
260+
buf.WriteString(notExpr)
261+
return buf.String()
262+
}
263+
247264
// Exists represents "EXISTS (subquery)".
248265
func (c *Cond) Exists(subquery interface{}) string {
249266
buf := newStringBuilder()

cond_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ func TestCond(t *testing.T) {
3535
"$$a LIKE $0": func() string { return newTestCond().Like("$a", "%Huan%") },
3636
"$$a ILIKE $0": func() string { return newTestCond().ILike("$a", "%Huan%") },
3737
"$$a NOT LIKE $0": func() string { return newTestCond().NotLike("$a", "%Huan%") },
38+
"$$a NOT ILIKE $0": func() string { return newTestCond().NotILike("$a", "%Huan%") },
3839
"$$a IS NULL": func() string { return newTestCond().IsNull("$a") },
3940
"$$a IS NOT NULL": func() string { return newTestCond().IsNotNull("$a") },
4041
"$$a BETWEEN $0 AND $1": func() string { return newTestCond().Between("$a", 123, 456) },
4142
"$$a NOT BETWEEN $0 AND $1": func() string { return newTestCond().NotBetween("$a", 123, 456) },
4243
"(1 = 1 OR 2 = 2 OR 3 = 3)": func() string { return newTestCond().Or("1 = 1", "2 = 2", "3 = 3") },
4344
"(1 = 1 AND 2 = 2 AND 3 = 3)": func() string { return newTestCond().And("1 = 1", "2 = 2", "3 = 3") },
45+
"NOT 1 = 1": func() string { return newTestCond().Not("1 = 1") },
4446
"EXISTS ($0)": func() string { return newTestCond().Exists(1) },
4547
"NOT EXISTS ($0)": func() string { return newTestCond().NotExists(1) },
4648
"$$a > ANY ($0, $1)": func() string { return newTestCond().Any("$a", ">", 1, 2) },

0 commit comments

Comments
 (0)