Merge pull request #168 from vallahaye/167-add-logical-not-and-not-ilike-comparison-operators

Add logical NOT and NOT ILIKE operators
This commit is contained in:
Huan Du
2024-09-10 15:49:16 +08:00
committed by GitHub
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -188,6 +188,15 @@ func (c *Cond) NotLike(field string, value interface{}) string {
return buf.String()
}
// NotILike represents "field NOT ILIKE value".
func (c *Cond) NotILike(field string, value interface{}) string {
buf := newStringBuilder()
buf.WriteString(Escape(field))
buf.WriteString(" NOT ILIKE ")
buf.WriteString(c.Args.Add(value))
return buf.String()
}
// IsNull represents "field IS NULL".
func (c *Cond) IsNull(field string) string {
buf := newStringBuilder()
@@ -244,6 +253,14 @@ func (c *Cond) And(andExpr ...string) string {
return buf.String()
}
// Not represents "NOT expr".
func (c *Cond) Not(notExpr string) string {
buf := newStringBuilder()
buf.WriteString("NOT ")
buf.WriteString(notExpr)
return buf.String()
}
// Exists represents "EXISTS (subquery)".
func (c *Cond) Exists(subquery interface{}) string {
buf := newStringBuilder()
+2
View File
@@ -35,12 +35,14 @@ func TestCond(t *testing.T) {
"$$a LIKE $0": func() string { return newTestCond().Like("$a", "%Huan%") },
"$$a ILIKE $0": func() string { return newTestCond().ILike("$a", "%Huan%") },
"$$a NOT LIKE $0": func() string { return newTestCond().NotLike("$a", "%Huan%") },
"$$a NOT ILIKE $0": func() string { return newTestCond().NotILike("$a", "%Huan%") },
"$$a IS NULL": func() string { return newTestCond().IsNull("$a") },
"$$a IS NOT NULL": func() string { return newTestCond().IsNotNull("$a") },
"$$a BETWEEN $0 AND $1": func() string { return newTestCond().Between("$a", 123, 456) },
"$$a NOT BETWEEN $0 AND $1": func() string { return newTestCond().NotBetween("$a", 123, 456) },
"(1 = 1 OR 2 = 2 OR 3 = 3)": func() string { return newTestCond().Or("1 = 1", "2 = 2", "3 = 3") },
"(1 = 1 AND 2 = 2 AND 3 = 3)": func() string { return newTestCond().And("1 = 1", "2 = 2", "3 = 3") },
"NOT 1 = 1": func() string { return newTestCond().Not("1 = 1") },
"EXISTS ($0)": func() string { return newTestCond().Exists(1) },
"NOT EXISTS ($0)": func() string { return newTestCond().NotExists(1) },
"$$a > ANY ($0, $1)": func() string { return newTestCond().Any("$a", ">", 1, 2) },