@@ -66,10 +66,9 @@ export class Builder extends NotTagged {
6666
6767 build ( before , parameters , types , options ) {
6868 const keyword = builders . map ( ( [ x , fn ] ) => ( { fn, i : before . search ( x ) } ) ) . sort ( ( a , b ) => a . i - b . i ) . pop ( )
69- if ( keyword . i === - 1 )
70- throw new Error ( 'Could not infer helper mode' )
71-
72- return keyword . fn ( this . first , this . rest , parameters , types , options )
69+ return keyword . i === - 1
70+ ? escapeIdentifiers ( this . first , options )
71+ : keyword . fn ( this . first , this . rest , parameters , types , options )
7372 }
7473}
7574
@@ -137,7 +136,7 @@ function values(first, rest, parameters, types, options) {
137136function select ( first , rest , parameters , types , options ) {
138137 typeof first === 'string' && ( first = [ first ] . concat ( rest ) )
139138 if ( Array . isArray ( first ) )
140- return first . map ( x => escapeIdentifier ( options . transform . column . to ? options . transform . column . to ( x ) : x ) ) . join ( ',' )
139+ return escapeIdentifiers ( first , options )
141140
142141 let value
143142 const columns = rest . length ? rest . flat ( ) : Object . keys ( first )
@@ -170,9 +169,7 @@ const builders = Object.entries({
170169
171170 insert ( first , rest , parameters , types , options ) {
172171 const columns = rest . length ? rest . flat ( ) : Object . keys ( Array . isArray ( first ) ? first [ 0 ] : first )
173- return '(' + columns . map ( x =>
174- escapeIdentifier ( options . transform . column . to ? options . transform . column . to ( x ) : x )
175- ) . join ( ',' ) + ')values' +
172+ return '(' + escapeIdentifiers ( columns , options ) + ')values' +
176173 valuesBuilder ( Array . isArray ( first ) ? first : [ first ] , parameters , types , columns , options )
177174 }
178175} ) . map ( ( [ x , fn ] ) => ( [ new RegExp ( '((?:^|[\\s(])' + x + '(?:$|[\\s(]))(?![\\s\\S]*\\1)' , 'i' ) , fn ] ) )
@@ -209,6 +206,10 @@ function typeHandlers(types) {
209206 } , { parsers : { } , serializers : { } } )
210207}
211208
209+ function escapeIdentifiers ( xs , { transform : { column } } ) {
210+ return xs . map ( x => escapeIdentifier ( column . to ? column . to ( x ) : x ) ) . join ( ',' )
211+ }
212+
212213export const escapeIdentifier = function escape ( str ) {
213214 return '"' + str . replace ( / " / g, '""' ) . replace ( / \. / g, '"."' ) + '"'
214215}
0 commit comments