@@ -199,7 +199,7 @@ function Postgres(a, b) {
199199 function nested ( first , rest ) {
200200 const o = Object . create ( notPromise )
201201 o . first = first
202- o . rest = rest
202+ o . rest = rest . flat ( )
203203 return o
204204 }
205205
@@ -222,12 +222,10 @@ function Postgres(a, b) {
222222 return connection
223223 }
224224
225- function array ( value ) {
226- return {
227- type : inferType ( value ) || 25 ,
228- array : true ,
229- value
230- }
225+ function array ( xs ) {
226+ const o = Object . create ( notPromise )
227+ o . array = xs
228+ return o
231229 }
232230
233231 function json ( value ) {
@@ -395,10 +393,7 @@ function Postgres(a, b) {
395393
396394 for ( let i = 1 ; i < xs . length ; i ++ ) {
397395 arg = args [ i - 1 ]
398- str += ( arg && arg . P === notPromise . P
399- ? parseHelper ( str , arg , xargs , types )
400- : parseValue ( arg , xargs , types )
401- ) + xs [ i ]
396+ str += parseArg ( str , arg , xargs , types ) + xs [ i ]
402397 }
403398
404399 return {
@@ -408,6 +403,21 @@ function Postgres(a, b) {
408403 }
409404 }
410405
406+ function parseArg ( str , arg , xargs , types ) {
407+ return arg && arg . P === notPromise . P
408+ ? arg . array
409+ ? parseArray ( arg . array , xargs , types )
410+ : parseHelper ( str , arg , xargs , types )
411+ : parseValue ( arg , xargs , types )
412+ }
413+
414+ function parseArray ( array , xargs , types ) {
415+ return array . length === 0 ? '\'{}\'' : 'array[' + array . map ( ( x ) => Array . isArray ( x )
416+ ? parseArray ( x , xargs , types )
417+ : parseValue ( x , xargs , types )
418+ ) . join ( ',' ) + ']'
419+ }
420+
411421 function parseHelper ( str , { first, rest } , xargs , types ) {
412422 xargs . dynamic = true
413423 if ( first !== null && typeof first === 'object' && typeof first [ 0 ] !== 'string' ) {
@@ -458,6 +468,8 @@ function Postgres(a, b) {
458468
459469 return Array . isArray ( x )
460470 ? x . reduce ( ( acc , x ) => acc + ( acc ? ',' : '' ) + addValue ( x , xargs , types ) , '' )
471+ : x && x . P === notPromise . P
472+ ? parseArg ( '' , x , xargs , types )
461473 : addValue ( x , xargs , types )
462474 }
463475
@@ -477,7 +489,7 @@ function Postgres(a, b) {
477489 return { type : 0 , value : x }
478490
479491 const value = x . type ? x . value : x
480- , type = x . array ? typeArrayMap [ x . type ] : ( x . type || inferType ( value ) )
492+ , type = x . type || inferType ( value )
481493
482494 return {
483495 type,
0 commit comments