Skip to content

Commit 85bca49

Browse files
committed
Support empty arrays in dynamic in - fixes #417
1 parent eeecc06 commit 85bca49

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
@@ -929,6 +929,16 @@ t('dynamic insert pluck', async() => {
929929
return [null, (await sql`insert into test ${ sql(x, 'a') } returning *`)[0].b, await sql`drop table test`]
930930
})
931931

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

0 commit comments

Comments
 (0)