Skip to content

Commit

Permalink
Support empty arrays in dynamic in - fixes #417
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Jul 22, 2022
1 parent eeecc06 commit 85bca49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ function select(first, rest, parameters, types, options) {

const builders = Object.entries({
values,
in: values,
in: (...xs) => {
const x = values(...xs)
return x === '()' ? '(null)' : x
},
select,
as: select,
returning: select,
Expand Down
12 changes: 11 additions & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,16 @@ t('dynamic insert pluck', async() => {
return [null, (await sql`insert into test ${ sql(x, 'a') } returning *`)[0].b, await sql`drop table test`]
})

t('dynamic in with empty array', async() => {
await sql`create table test (a int)`
await sql`insert into test values (1)`
return [
(await sql`select * from test where null in ${ sql([]) }`).count,
0,
await sql`drop table test`
]
})

t('dynamic in after insert', async() => {
await sql`create table test (a int, b text)`
const [{ x }] = await sql`
Expand Down Expand Up @@ -2218,4 +2228,4 @@ t('Insert array with undefined transform', async() => {
(await sql`select x from test`)[0].x[0],
await sql`drop table test`
]
})
})

0 comments on commit 85bca49

Please sign in to comment.