@@ -218,7 +218,8 @@ describe('Builder', function() {
218
218
values : { name : 'John' , surname : 'Doe' }
219
219
} ) ;
220
220
221
- expect ( result . query ) . to . be . equal ( 'insert into "users" ("name", "surname") values (\'John\', \'Doe\');' ) ;
221
+ expect ( result . query ) . to . be . equal ( 'insert into "users" ("name", "surname") values ' +
222
+ '(\'John\', \'Doe\');' ) ;
222
223
expect ( result . values ) . to . not . be . ok ;
223
224
} ) ;
224
225
@@ -238,23 +239,24 @@ describe('Builder', function() {
238
239
}
239
240
) ;
240
241
241
- it ( 'should throw error if identifier contains more than one dot ' , function ( ) {
242
+ it ( 'shouldn\'t wrap identifiers that already wrapped ' , function ( ) {
242
243
jsonSql . configure ( {
243
244
wrappedIdentifiers : true
244
245
} ) ;
245
246
246
- expect ( function ( ) {
247
- jsonSql . build ( {
248
- type : 'insert' ,
249
- table : '"users"' ,
250
- values : {
251
- 'users.a.b' : 1
252
- }
253
- } ) ;
254
- } ) . to . throw ( 'Identifier "users.a.b" contains more than one dot' ) ;
247
+ var result = jsonSql . build ( {
248
+ type : 'insert' ,
249
+ table : '"users"' ,
250
+ values : {
251
+ '"name"' : 'John' ,
252
+ '"users"."age"' : 22
253
+ }
254
+ } ) ;
255
+
256
+ expect ( result . query ) . to . be . equal ( 'insert into "users" ("name", "users"."age") values ($p1, 22);' ) ;
255
257
} ) ;
256
258
257
- it ( 'shouldn\'t wrap identifiers twice ' , function ( ) {
259
+ it ( 'shouldn\'t split identifiers by dots inside quotes ' , function ( ) {
258
260
jsonSql . configure ( {
259
261
wrappedIdentifiers : true
260
262
} ) ;
@@ -263,15 +265,27 @@ describe('Builder', function() {
263
265
type : 'insert' ,
264
266
table : '"users"' ,
265
267
values : {
266
- '"name"' : 'John' ,
267
- '"users"."age"' : 22
268
+ '"users.age"' : 22
268
269
}
269
270
} ) ;
270
271
271
- expect ( result . query ) . to . be . equal ( 'insert into "users" ("name", "users"."age") values ($p1, 22);' ) ;
272
+ expect ( result . query ) . to . be . equal ( 'insert into "users" ("users.age") values (22);' ) ;
273
+ } ) ;
274
+
275
+ it ( 'shouldn\'t wrap asterisk identifier parts' , function ( ) {
276
+ jsonSql . configure ( {
277
+ wrappedIdentifiers : true
278
+ } ) ;
279
+
280
+ var result = jsonSql . build ( {
281
+ fields : [ 'users.*' ] ,
282
+ table : '"users"'
283
+ } ) ;
284
+
285
+ expect ( result . query ) . to . be . equal ( 'select "users".* from "users";' ) ;
272
286
} ) ;
273
287
274
- it ( 'should wrap identifiers with dots' , function ( ) {
288
+ it ( 'should split identifiers by dots and wrap each part ' , function ( ) {
275
289
jsonSql . configure ( {
276
290
wrappedIdentifiers : true
277
291
} ) ;
0 commit comments