@@ -35,6 +35,10 @@ const baseOperations = {
35
35
}
36
36
} ;
37
37
38
+ function escape ( identifier ) {
39
+ return `\`${ identifier . replace ( / ` / g, "``" ) } \`` ;
40
+ }
41
+
38
42
describe ( "makeQueryTemplate" , ( ) => {
39
43
it ( "makeQueryTemplate null table" , ( ) => {
40
44
const source = { } ;
@@ -437,6 +441,25 @@ describe("makeQueryTemplate", () => {
437
441
) ;
438
442
assert . deepStrictEqual ( params , [ "val1" , "val2" ] ) ;
439
443
} ) ;
444
+
445
+ it ( "makeQueryTemplate names" , ( ) => {
446
+ const source = { name : "db" , dialect : "mysql" , escape} ;
447
+ let operations = {
448
+ ...baseOperations ,
449
+ select : {
450
+ columns : [ "col1" , "col2" , "col3" ]
451
+ } ,
452
+ names : [
453
+ { column : "col1" , name : "name1" } ,
454
+ { column : "col2" , name : "name2" } ,
455
+ { column : "col3" , name : "name3" }
456
+ ]
457
+ } ;
458
+
459
+ const [ parts , ...params ] = makeQueryTemplate ( operations , source ) ;
460
+ assert . deepStrictEqual ( parts . join ( "?" ) , "SELECT `col1` AS `name1`, `col2` AS `name2`, `col3` AS `name3` FROM `table1`" ) ;
461
+ assert . deepStrictEqual ( params , [ ] ) ;
462
+ } ) ;
440
463
} ) ;
441
464
442
465
describe ( "__table" , ( ) => {
@@ -585,6 +608,24 @@ describe("__table", () => {
585
608
[ { name : "a" , type : "number" } , { name : "b" , type : "number" } , { name : "c" , type : "number" } ]
586
609
) ;
587
610
} ) ;
611
+
612
+ it ( "__table names" , ( ) => {
613
+ const operations = {
614
+ ...EMPTY_TABLE_DATA . operations ,
615
+ names : [ { column : "a" , name : "nameA" } ]
616
+ } ;
617
+ assert . deepStrictEqual ( __table ( source , operations ) , [ { nameA : 1 , b : 2 , c : 3 } , { nameA : 2 , b : 4 , c : 6 } , { nameA : 3 , b : 6 , c : 9 } ] ) ;
618
+ source . columns = [ "a" , "b" , "c" ] ;
619
+ assert . deepStrictEqual (
620
+ __table ( source , operations ) . columns ,
621
+ [ "nameA" , "b" , "c" ]
622
+ ) ;
623
+ source . schema = [ { name : "a" , type : "number" } , { name : "b" , type : "number" } , { name : "c" , type : "number" } ] ;
624
+ assert . deepStrictEqual (
625
+ __table ( source , operations ) . schema ,
626
+ [ { name : "nameA" , type : "number" } , { name : "b" , type : "number" } , { name : "c" , type : "number" } ]
627
+ ) ;
628
+ } ) ;
588
629
} ) ;
589
630
590
631
describe ( "getTypeValidator filters accurately" , ( ) => {
0 commit comments