Skip to content

Commit 545d48b

Browse files
larrymjordanmclark4386
authored andcommitted
Query in support with slice args. (#267)
* [Fix] issue when using IN more than once '?' wildcards * slices with in
1 parent 3620fd3 commit 545d48b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

query_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/gobuffalo/uuid"
78
"github.com/stretchr/testify/require"
89
)
910

@@ -48,6 +49,26 @@ func Test_Where_In(t *testing.T) {
4849
})
4950
}
5051

52+
func Test_Where_In_Slice(t *testing.T) {
53+
r := require.New(t)
54+
transaction(func(tx *Connection) {
55+
u1 := &Song{Title: "A"}
56+
u2 := &Song{Title: "A"}
57+
u3 := &Song{Title: "A"}
58+
err := tx.Create(u1)
59+
r.NoError(err)
60+
err = tx.Create(u2)
61+
r.NoError(err)
62+
err = tx.Create(u3)
63+
r.NoError(err)
64+
65+
songs := []Song{}
66+
err = tx.Where("id in (?)", []uuid.UUID{u1.ID, u3.ID}).Where("title = ?", "A").All(&songs)
67+
r.NoError(err)
68+
r.Len(songs, 2)
69+
})
70+
}
71+
5172
func Test_Where_In_Complex(t *testing.T) {
5273
r := require.New(t)
5374
transaction(func(tx *Connection) {

sql_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ func (sq *sqlBuilder) compile() {
8888
}
8989

9090
if inRegex.MatchString(sq.sql) {
91-
s, _, err := sqlx.In(sq.sql, sq.Args())
91+
s, args, err := sqlx.In(sq.sql, sq.Args()...)
9292
if err == nil {
9393
sq.sql = s
94+
sq.args = args
9495
}
9596
}
9697
sq.sql = sq.Query.Connection.Dialect.TranslateSQL(sq.sql)

0 commit comments

Comments
 (0)