Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logical NOT and NOT ILIKE operators #168

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions cond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
Loading