mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
feat(cond): add logical NOT and NOT ILIKE operators
Add Cond.Not and Cond.NotILike to build NOT and NOT ILIKE expressions. Closes #167
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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) },
|
||||
|
||||
Reference in New Issue
Block a user