Skip to content

Commit 342bf55

Browse files
committed
Add support for array of fragments
1 parent 1adc113 commit 342bf55

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/types.js

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const defaultHandlers = typeHandlers(types)
9999
export function stringify(q, string, value, parameters, types, options) { // eslint-disable-line
100100
for (let i = 1; i < q.strings.length; i++) {
101101
string += (
102+
value && value[0] instanceof Query ? value.reduce((acc, x) => acc + ' ' + fragment(x, parameters, types), '') :
102103
value instanceof Query ? fragment(value, parameters, types) :
103104
value instanceof Identifier ? value.value :
104105
value instanceof Builder ? value.build(string, parameters, types, options) :

tests/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -2100,3 +2100,14 @@ t('Supports nested fragments with parameters', async() => {
21002100
await sql`drop table test`
21012101
]
21022102
})
2103+
2104+
t('Supports arrays of fragments', async() => {
2105+
const [{ x }] = await sql`
2106+
${ [sql`select`, sql`1`, sql`as`, sql`x`] }
2107+
`
2108+
2109+
return [
2110+
1,
2111+
x
2112+
]
2113+
})

0 commit comments

Comments
 (0)