@@ -66,10 +66,9 @@ export class Builder extends NotTagged {
66
66
67
67
build ( before , parameters , types , options ) {
68
68
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 )
73
72
}
74
73
}
75
74
@@ -137,7 +136,7 @@ function values(first, rest, parameters, types, options) {
137
136
function select ( first , rest , parameters , types , options ) {
138
137
typeof first === 'string' && ( first = [ first ] . concat ( rest ) )
139
138
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 )
141
140
142
141
let value
143
142
const columns = rest . length ? rest . flat ( ) : Object . keys ( first )
@@ -170,9 +169,7 @@ const builders = Object.entries({
170
169
171
170
insert ( first , rest , parameters , types , options ) {
172
171
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' +
176
173
valuesBuilder ( Array . isArray ( first ) ? first : [ first ] , parameters , types , columns , options )
177
174
}
178
175
} ) . map ( ( [ x , fn ] ) => ( [ new RegExp ( '((?:^|[\\s(])' + x + '(?:$|[\\s(]))(?![\\s\\S]*\\1)' , 'i' ) , fn ] ) )
@@ -209,6 +206,10 @@ function typeHandlers(types) {
209
206
} , { parsers : { } , serializers : { } } )
210
207
}
211
208
209
+ function escapeIdentifiers ( xs , { transform : { column } } ) {
210
+ return xs . map ( x => escapeIdentifier ( column . to ? column . to ( x ) : x ) ) . join ( ',' )
211
+ }
212
+
212
213
export const escapeIdentifier = function escape ( str ) {
213
214
return '"' + str . replace ( / " / g, '""' ) . replace ( / \. / g, '"."' ) + '"'
214
215
}
0 commit comments