Skip to content

Commit

Permalink
fix issue with bigger array query returning zero results
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed Aug 28, 2023
1 parent 27c20a9 commit 361a8b3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/worker/executors/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,23 @@ export class Select extends BaseFetch {
else {
this.results = output;
}
return promiseResolve();
};
const executeWhere = (whereQuery) => {
const executeWhere = (whereQuery): Promise<any> => {
const select = new Select({
from: this.query.from,
where: whereQuery as any
}, this.util);
return select.execute().then(results => {
this.results = results;
onSuccess();
return onSuccess();
});
};
const processFirstQry = () => {
const processFirstQry = (): Promise<any> => {
let whereQueryToProcess = whereQuery.shift();
const whereQueryOr = whereQueryToProcess[QUERY_OPTION.Or];
if (whereQueryOr) {
if (Array.isArray(whereQueryOr)) {
if (isArray(whereQueryOr)) {
operation = QUERY_OPTION.Or;
return executeWhere(whereQueryOr);
}
Expand Down
8 changes: 4 additions & 4 deletions src/worker/executors/select/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ class Join {
whereQueryModified: whereQryParam
}
}
const result = removeJoinColumn(whereQuery);
const whereQryAfterJoin = result.whereQryAfterJoin;
query.where = result.whereQueryModified;
if (result.isWhereEmpty) {
const removeJoinColumnResult = removeJoinColumn(whereQuery);
const whereQryAfterJoin = removeJoinColumnResult.whereQryAfterJoin;
query.where = removeJoinColumnResult.whereQueryModified;
if (removeJoinColumnResult.isWhereEmpty) {
delete query.where;
}
const joinQuery = this.joinQueryStack_[0];
Expand Down
71 changes: 71 additions & 0 deletions test/cases/select/select_complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,75 @@ describe('Test select complex case', function () {
done(err);
})
});

it(`SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
where orderId<1000000 && shipperId=2 and ((employeeId=4 and customerId=34) or (employeeId=4 and customerId=76)) order by orderid asc
`, function (done) {
con.select({
from: "Orders",
order: {
by: 'customerId',
type: 'asc' //supprted sort type is - asc,desc
},
where: [{
orderId: {
'<': 1000000
}
}, {
shipperId: 2,
},
[{
employeeId: 4,
customerId: 34,
}, {
or: {
employeeId: 4,
customerId: 76
}
}],
]
}).then(function (results) {
expect(results).to.be.an('array').length(3);
const expectedIds = results.map(result => result.orderId);
expect(expectedIds).eql([10250, 10252, 10302])
done();
}).catch(done)
});

it(`SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
where shipperId=2 and ((employeeId=4 and customerId=34) or (employeeId=4 and customerId=76)) and orderId<1000000 order by orderid asc
`, function (done) {
con.select({
from: "Orders",
order: {
by: 'customerId',
type: 'asc' //supprted sort type is - asc,desc
},
where: [{
shipperId: 2,
},
[{
employeeId: 4,
customerId: 34,
}, {
or: {
employeeId: 4,
customerId: 76
}
}],
{
orderId: {
'<': 1000000
}
},
]
}).then(function (results) {
expect(results).to.be.an('array').length(3);
const expectedIds = results.map(result => result.orderId);
expect(expectedIds).eql([10250, 10252, 10302])
done();
}).catch(done)
});
});

0 comments on commit 361a8b3

Please sign in to comment.