@@ -96,37 +96,35 @@ export function handleValue(x, parameters, types, options) {
9696
9797const defaultHandlers = typeHandlers ( types )
9898
99- export function stringify ( q , string , value , parameters , types , o ) { // eslint-disable-line
99+ export function stringify ( q , string , value , parameters , types , options ) { // eslint-disable-line
100100 for ( let i = 1 ; i < q . strings . length ; i ++ ) {
101- string += (
102- value && value [ 0 ] instanceof Query ? value . reduce ( ( acc , x ) => acc + ' ' + fragment ( x , parameters , types , o ) , '' ) :
103- value instanceof Query ? fragment ( value , parameters , types , o ) :
104- value instanceof Identifier ? value . value :
105- value instanceof Builder ? value . build ( string , parameters , types , o ) :
106- handleValue ( value , parameters , types , o )
107- ) + q . strings [ i ]
101+ string += ( stringifyValue ( string , value , parameters , types , options ) ) + q . strings [ i ]
108102 value = q . args [ i ]
109103 }
110104
111105 return string
112106}
113107
108+ function stringifyValue ( string , value , parameters , types , o ) {
109+ return (
110+ value instanceof Builder ? value . build ( string , parameters , types , o ) :
111+ value instanceof Query ? fragment ( value , parameters , types , o ) :
112+ value instanceof Identifier ? value . value :
113+ value && value [ 0 ] instanceof Query ? value . reduce ( ( acc , x ) => acc + ' ' + fragment ( x , parameters , types , o ) , '' ) :
114+ handleValue ( value , parameters , types , o )
115+ )
116+ }
117+
114118function fragment ( q , parameters , types , options ) {
115119 q . fragment = true
116120 return stringify ( q , q . strings [ 0 ] , q . args [ 0 ] , parameters , types , options )
117121}
118122
119123function valuesBuilder ( first , parameters , types , columns , options ) {
120- let value
121124 return first . map ( row =>
122- '(' + columns . map ( column => {
123- value = row [ column ]
124- return (
125- value instanceof Query ? fragment ( value , parameters , types ) :
126- value instanceof Identifier ? value . value :
127- handleValue ( value , parameters , types , options )
128- )
129- } ) . join ( ',' ) + ')'
125+ '(' + columns . map ( column =>
126+ stringifyValue ( 'values' , row [ column ] , parameters , types , options )
127+ ) . join ( ',' ) + ')'
130128 ) . join ( ',' )
131129}
132130
@@ -146,7 +144,7 @@ function select(first, rest, parameters, types, options) {
146144 return columns . map ( x => {
147145 value = first [ x ]
148146 return (
149- value instanceof Query ? fragment ( value , parameters , types ) :
147+ value instanceof Query ? fragment ( value , parameters , types , options ) :
150148 value instanceof Identifier ? value . value :
151149 handleValue ( value , parameters , types , options )
152150 ) + ' as ' + escapeIdentifier ( options . transform . column . to ? options . transform . column . to ( x ) : x )
0 commit comments