Skip to content

Commit

Permalink
Merge pull request #278 from ujjwalguptaofficial/fix-order-typing
Browse files Browse the repository at this point in the history
update select query order type to accept array of order query
  • Loading branch information
ujjwalguptaofficial authored Jul 21, 2022
2 parents af5f5ec + 01415f2 commit 4b4043c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export interface ISelectQuery {
where?: IWhereQuery | IWhereQuery[];
skip?: number;
limit?: number;
order?: IOrderQuery;
order?: IOrderQuery | IOrderQuery[];
groupBy?: string | string[] | { [columnName: string]: [ICaseOption] };
aggregate?: IAggregateOption;
distinct?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/worker/executors/select/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ISelectQuery, QUERY_OPTION, IDB_MODE, API, IWhereQuery, promiseResolve } from "@/common";
import { ISelectQuery, QUERY_OPTION, IDB_MODE, API, IWhereQuery, promiseResolve, IOrderQuery } from "@/common";
import { IDBUtil } from "@/worker/idbutil";
import { QueryHelper } from "@worker/executors/query_helper";
import { DbMeta } from "@/worker/model";
Expand Down Expand Up @@ -58,8 +58,8 @@ export class Select extends BaseFetch {
this.limitRecord = query.limit;
}
if (query.order) {
if (isArray(query.order) || query.order.case || isObject(query.order.by)) {
this.query.order.idbSorting = false;
if (isArray(query.order) || (query.order as IOrderQuery).case || isObject((query.order as IOrderQuery).by)) {
((query.order as IOrderQuery).idbSorting) = false;
}
this.setLimitAndSkipEvaluationAtEnd_();
}
Expand Down
17 changes: 9 additions & 8 deletions src/worker/executors/select/not_where.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Select } from "./index";
import { LogHelper, promiseReject, getError } from "@/worker/utils";
import { ERROR_TYPE, promise } from "@/common";
import { LogHelper, promiseReject } from "@/worker/utils";
import { ERROR_TYPE, IOrderQuery, promise } from "@/common";

export const executeWhereUndefinedLogic = function (this: Select) {
let cursorRequest: IDBRequest;
if (this.query.order && this.query.order.idbSorting !== false && this.query.order.by) {
if (this.objectStore.indexNames.contains(this.query.order.by as string)) {
const orderType: IDBCursorDirection = this.query.order.type &&
this.query.order.type.toLowerCase() === 'desc' ? 'prev' : 'next';
const orderQuery = this.query.order;
if (orderQuery && (orderQuery as IOrderQuery).idbSorting !== false && (orderQuery as IOrderQuery).by) {
if (this.objectStore.indexNames.contains((orderQuery as IOrderQuery).by as string)) {
const orderType: IDBCursorDirection = (orderQuery as IOrderQuery).type &&
(orderQuery as IOrderQuery).type.toLowerCase() === 'desc' ? 'prev' : 'next';
this.sorted = true;
cursorRequest = this.objectStore.index(this.query.order.by as string).
cursorRequest = this.objectStore.index((orderQuery as IOrderQuery).by as string).
openCursor(null, orderType);
}
else {
return promiseReject(
new LogHelper(
ERROR_TYPE.ColumnNotExist,
{ column: this.query.order.by, isOrder: true }
{ column: (orderQuery as IOrderQuery).by, isOrder: true }
)
);
}
Expand Down

0 comments on commit 4b4043c

Please sign in to comment.