File tree 3 files changed +80
-8
lines changed
src/worker/executors/select
3 files changed +80
-8
lines changed Original file line number Diff line number Diff line change @@ -150,22 +150,23 @@ export class Select extends BaseFetch {
150
150
else {
151
151
this . results = output ;
152
152
}
153
+ return promiseResolve ( ) ;
153
154
} ;
154
- const executeWhere = ( whereQuery ) => {
155
+ const executeWhere = ( whereQuery ) : Promise < any > => {
155
156
const select = new Select ( {
156
157
from : this . query . from ,
157
158
where : whereQuery as any
158
159
} , this . util ) ;
159
160
return select . execute ( ) . then ( results => {
160
161
this . results = results ;
161
- onSuccess ( ) ;
162
+ return onSuccess ( ) ;
162
163
} ) ;
163
164
} ;
164
- const processFirstQry = ( ) => {
165
+ const processFirstQry = ( ) : Promise < any > => {
165
166
let whereQueryToProcess = whereQuery . shift ( ) ;
166
167
const whereQueryOr = whereQueryToProcess [ QUERY_OPTION . Or ] ;
167
168
if ( whereQueryOr ) {
168
- if ( Array . isArray ( whereQueryOr ) ) {
169
+ if ( isArray ( whereQueryOr ) ) {
169
170
operation = QUERY_OPTION . Or ;
170
171
return executeWhere ( whereQueryOr ) ;
171
172
}
Original file line number Diff line number Diff line change @@ -126,10 +126,10 @@ class Join {
126
126
whereQueryModified : whereQryParam
127
127
}
128
128
}
129
- const result = removeJoinColumn ( whereQuery ) ;
130
- const whereQryAfterJoin = result . whereQryAfterJoin ;
131
- query . where = result . whereQueryModified ;
132
- if ( result . isWhereEmpty ) {
129
+ const removeJoinColumnResult = removeJoinColumn ( whereQuery ) ;
130
+ const whereQryAfterJoin = removeJoinColumnResult . whereQryAfterJoin ;
131
+ query . where = removeJoinColumnResult . whereQueryModified ;
132
+ if ( removeJoinColumnResult . isWhereEmpty ) {
133
133
delete query . where ;
134
134
}
135
135
const joinQuery = this . joinQueryStack_ [ 0 ] ;
Original file line number Diff line number Diff line change @@ -530,4 +530,75 @@ describe('Test select complex case', function () {
530
530
done ( err ) ;
531
531
} )
532
532
} ) ;
533
+
534
+ it ( `SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
535
+ FROM Orders
536
+ where orderId<1000000 && shipperId=2 and ((employeeId=4 and customerId=34) or (employeeId=4 and customerId=76)) order by orderid asc
537
+ ` , function ( done ) {
538
+ con . select ( {
539
+ from : "Orders" ,
540
+ order : {
541
+ by : 'customerId' ,
542
+ type : 'asc' //supprted sort type is - asc,desc
543
+ } ,
544
+ where : [ {
545
+ orderId : {
546
+ '<' : 1000000
547
+ }
548
+ } , {
549
+ shipperId : 2 ,
550
+ } ,
551
+ [ {
552
+ employeeId : 4 ,
553
+ customerId : 34 ,
554
+ } , {
555
+ or : {
556
+ employeeId : 4 ,
557
+ customerId : 76
558
+ }
559
+ } ] ,
560
+ ]
561
+ } ) . then ( function ( results ) {
562
+ expect ( results ) . to . be . an ( 'array' ) . length ( 3 ) ;
563
+ const expectedIds = results . map ( result => result . orderId ) ;
564
+ expect ( expectedIds ) . eql ( [ 10250 , 10252 , 10302 ] )
565
+ done ( ) ;
566
+ } ) . catch ( done )
567
+ } ) ;
568
+
569
+ it ( `SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
570
+ FROM Orders
571
+ where shipperId=2 and ((employeeId=4 and customerId=34) or (employeeId=4 and customerId=76)) and orderId<1000000 order by orderid asc
572
+ ` , function ( done ) {
573
+ con . select ( {
574
+ from : "Orders" ,
575
+ order : {
576
+ by : 'customerId' ,
577
+ type : 'asc' //supprted sort type is - asc,desc
578
+ } ,
579
+ where : [ {
580
+ shipperId : 2 ,
581
+ } ,
582
+ [ {
583
+ employeeId : 4 ,
584
+ customerId : 34 ,
585
+ } , {
586
+ or : {
587
+ employeeId : 4 ,
588
+ customerId : 76
589
+ }
590
+ } ] ,
591
+ {
592
+ orderId : {
593
+ '<' : 1000000
594
+ }
595
+ } ,
596
+ ]
597
+ } ) . then ( function ( results ) {
598
+ expect ( results ) . to . be . an ( 'array' ) . length ( 3 ) ;
599
+ const expectedIds = results . map ( result => result . orderId ) ;
600
+ expect ( expectedIds ) . eql ( [ 10250 , 10252 , 10302 ] )
601
+ done ( ) ;
602
+ } ) . catch ( done )
603
+ } ) ;
533
604
} ) ;
You can’t perform that action at this time.
0 commit comments