@@ -304,38 +304,42 @@ export default function Postgres(url, options) {
304
304
305
305
function parse ( xs , args = [ ] ) {
306
306
const xargs = [ ]
307
+ , types = [ ]
308
+
307
309
let str = xs [ 0 ]
308
310
let arg
309
311
310
312
for ( let i = 1 ; i < xs . length ; i ++ ) {
311
313
arg = args [ i - 1 ]
312
314
str += ( arg . rows
313
- ? parseRows ( arg . rows , xargs )
315
+ ? parseRows ( arg . rows , xargs , types )
314
316
: arg . row
315
- ? parseRow ( arg . row , xargs )
316
- : parseValue ( arg , xargs )
317
+ ? parseRow ( arg . row , xargs , types )
318
+ : parseValue ( arg , xargs , types )
317
319
) + xs [ i ]
318
320
}
319
321
320
322
return {
321
- sig : args . length === xargs . length ? xargs . map ( x => x . type ) + str : null ,
323
+ sig : ! xargs . dynamic && types + str ,
322
324
str : str . trim ( ) ,
323
325
args : xargs
324
326
}
325
327
}
326
328
327
- function parseRows ( rows , xargs ) {
328
- return rows . map ( row => parseRow ( row , xargs ) ) . join ( ',' )
329
+ function parseRows ( rows , xargs , types ) {
330
+ xargs . dynamic = true
331
+ return rows . map ( row => parseRow ( row , xargs , types ) ) . join ( ',' )
329
332
}
330
333
331
- function parseRow ( row , xargs ) {
332
- return '(' + row . map ( x => parseValue ( x , xargs ) ) . join ( ',' ) + ')'
334
+ function parseRow ( row , xargs , types ) {
335
+ return '(' + row . map ( x => parseValue ( x , xargs , types ) ) . join ( ',' ) + ')'
333
336
}
334
337
335
- function parseValue ( x , xargs ) {
338
+ function parseValue ( x , xargs , types ) {
336
339
const value = x . value ? x . value : x
337
340
, type = x . type || ( Array . isArray ( value ) ? typeArrayMap [ inferType ( value ) ] : inferType ( value ) )
338
341
342
+ types . push ( type )
339
343
return '$' + xargs . push ( {
340
344
type,
341
345
value : type
0 commit comments