Skip to content

Commit ebceb91

Browse files
authored
Merge pull request #159 from abanoub-fathy/add-ILIKE-helper-method
Add ilike helper method
2 parents 3282717 + 4b8a96c commit ebceb91

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ There are many methods for building conditions.
151151
- [Cond.In](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.In): `field IN (value1, value2, ...)`.
152152
- [Cond.NotIn](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.NotIn): `field NOT IN (value1, value2, ...)`.
153153
- [Cond.Like](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.Like): `field LIKE value`.
154+
- [Cond.ILike](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.ILike): `field ILIKE value`.
154155
- [Cond.NotLike](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.NotLike): `field NOT LIKE value`.
155156
- [Cond.Between](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.Between): `field BETWEEN lower AND upper`.
156157
- [Cond.NotBetween](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Cond.NotBetween): `field NOT BETWEEN lower AND upper`.

cond.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ func (c *Cond) Like(field string, value interface{}) string {
170170
return buf.String()
171171
}
172172

173+
// ILike represents "field ILIKE value".
174+
func (c *Cond) ILike(field string, value interface{}) string {
175+
buf := newStringBuilder()
176+
buf.WriteString(Escape(field))
177+
buf.WriteString(" ILIKE ")
178+
buf.WriteString(c.Args.Add(value))
179+
return buf.String()
180+
}
181+
173182
// NotLike represents "field NOT LIKE value".
174183
func (c *Cond) NotLike(field string, value interface{}) string {
175184
buf := newStringBuilder()

cond_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestCond(t *testing.T) {
3333
"$$a IN ($0, $1, $2)": func() string { return newTestCond().In("$a", 1, 2, 3) },
3434
"$$a NOT IN ($0, $1, $2)": func() string { return newTestCond().NotIn("$a", 1, 2, 3) },
3535
"$$a LIKE $0": func() string { return newTestCond().Like("$a", "%Huan%") },
36+
"$$a ILIKE $0": func() string { return newTestCond().ILike("$a", "%Huan%") },
3637
"$$a NOT LIKE $0": func() string { return newTestCond().NotLike("$a", "%Huan%") },
3738
"$$a IS NULL": func() string { return newTestCond().IsNull("$a") },
3839
"$$a IS NOT NULL": func() string { return newTestCond().IsNotNull("$a") },

0 commit comments

Comments
 (0)