Skip to content

Commit 35c8a3f

Browse files
committed
Support empty arrays in dynamic in - fixes #417
1 parent 9fcfc2e commit 35c8a3f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/types.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ function select(first, rest, parameters, types, options) {
153153

154154
const builders = Object.entries({
155155
values,
156-
in: values,
156+
in: (...xs) => {
157+
const x = values(...xs)
158+
return x === '()' ? '(null)' : x
159+
},
157160
select,
158161
as: select,
159162
returning: select,

tests/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,16 @@ t('dynamic insert pluck', async() => {
930930
return [null, (await sql`insert into test ${ sql(x, 'a') } returning *`)[0].b, await sql`drop table test`]
931931
})
932932

933+
t('dynamic in with empty array', async() => {
934+
await sql`create table test (a int)`
935+
await sql`insert into test values (1)`
936+
return [
937+
(await sql`select * from test where null in ${ sql([]) }`).count,
938+
0,
939+
await sql`drop table test`
940+
]
941+
})
942+
933943
t('dynamic in after insert', async() => {
934944
await sql`create table test (a int, b text)`
935945
const [{ x }] = await sql`
@@ -2216,4 +2226,4 @@ t('Insert array with undefined transform', async() => {
22162226
(await sql`select x from test`)[0].x[0],
22172227
await sql`drop table test`
22182228
]
2219-
})
2229+
})

0 commit comments

Comments
 (0)