diff --git a/cond.go b/cond.go index 5ac6ff6..94ae715 100644 --- a/cond.go +++ b/cond.go @@ -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() diff --git a/cond_test.go b/cond_test.go index 15807b4..5c26506 100644 --- a/cond_test.go +++ b/cond_test.go @@ -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) },