Skip to content

Commit

Permalink
Merge pull request #159 from abanoub-fathy/add-ILIKE-helper-method
Browse files Browse the repository at this point in the history
Add ilike helper method
  • Loading branch information
huandu authored Jul 26, 2024
2 parents 3282717 + 4b8a96c commit ebceb91
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ There are many methods for building conditions.
- [Cond.In](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.In): `field IN (value1, value2, ...)`.
- [Cond.NotIn](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.NotIn): `field NOT IN (value1, value2, ...)`.
- [Cond.Like](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.Like): `field LIKE value`.
- [Cond.ILike](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.ILike): `field ILIKE value`.
- [Cond.NotLike](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.NotLike): `field NOT LIKE value`.
- [Cond.Between](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.Between): `field BETWEEN lower AND upper`.
- [Cond.NotBetween](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.NotBetween): `field NOT BETWEEN lower AND upper`.
Expand Down
9 changes: 9 additions & 0 deletions cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ func (c *Cond) Like(field string, value interface{}) string {
return buf.String()
}

// ILike represents "field ILIKE value".
func (c *Cond) ILike(field string, value interface{}) string {
buf := newStringBuilder()
buf.WriteString(Escape(field))
buf.WriteString(" ILIKE ")
buf.WriteString(c.Args.Add(value))
return buf.String()
}

// NotLike represents "field NOT LIKE value".
func (c *Cond) NotLike(field string, value interface{}) string {
buf := newStringBuilder()
Expand Down
1 change: 1 addition & 0 deletions cond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestCond(t *testing.T) {
"$$a IN ($0, $1, $2)": func() string { return newTestCond().In("$a", 1, 2, 3) },
"$$a NOT IN ($0, $1, $2)": func() string { return newTestCond().NotIn("$a", 1, 2, 3) },
"$$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 IS NULL": func() string { return newTestCond().IsNull("$a") },
"$$a IS NOT NULL": func() string { return newTestCond().IsNotNull("$a") },
Expand Down

0 comments on commit ebceb91

Please sign in to comment.