Skip to content

Commit

Permalink
JsonQL update
Browse files Browse the repository at this point in the history
  • Loading branch information
grassick committed Mar 18, 2021
1 parent 2734522 commit b411b61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/database/QueryCompiler.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema, Row, Variable } from "mwater-expressions";
import { QueryOptions } from "./Database";
import { JsonQL } from "jsonql";
import { JsonQLQuery } from "jsonql";
export declare class QueryCompiler {
schema: Schema;
variables: Variable[];
Expand All @@ -15,7 +15,7 @@ export declare class QueryCompiler {
* that queries may have, so we normalize to c0, c1, etc. in the query
*/
compileQuery(options: QueryOptions): {
jsonql: JsonQL;
jsonql: JsonQLQuery;
rowMapper: (row: Row) => Row;
};
}
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/database/QueryCompiler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Schema, ExprUtils, ExprCompiler, Row, Variable } from "mwater-expressions";
import { QueryOptions } from "./Database";
import * as _ from "lodash";
import { JsonQL } from "jsonql";
import { JsonQLQuery, JsonQLSelectQuery } from "jsonql";

export class QueryCompiler {
schema: Schema
Expand All @@ -18,12 +18,12 @@ export class QueryCompiler {
* rows to the ones requested by the query. This is necessary due to invalid select aliases
* that queries may have, so we normalize to c0, c1, etc. in the query
*/
compileQuery(options: QueryOptions): { jsonql: JsonQL, rowMapper: (row: Row) => Row } {
compileQuery(options: QueryOptions): { jsonql: JsonQLQuery, rowMapper: (row: Row) => Row } {
const exprUtils = new ExprUtils(this.schema, this.variables)
const exprCompiler = new ExprCompiler(this.schema, this.variables, this.variableValues)

// Create shell of query
const query: JsonQL = {
const query: JsonQLSelectQuery = {
type: "query",
selects: [],
from: exprCompiler.compileTable(options.from, "main"),
Expand Down Expand Up @@ -68,7 +68,7 @@ export class QueryCompiler {

// Add group by if not aggregate
if (isAggr && exprUtils.getExprAggrStatus(colExpr) !== "aggregate") {
query.groupBy.push(colIndex + 1)
query.groupBy!.push(colIndex + 1)
}
})

Expand All @@ -82,11 +82,11 @@ export class QueryCompiler {
alias: `o_${index}`
})

query.orderBy.push({ ordinal: colKeys.length + index + 1, direction: order.dir, nulls: (order.dir === "desc" ? "last" : "first") })
query.orderBy!.push({ ordinal: colKeys.length + index + 1, direction: order.dir, nulls: (order.dir === "desc" ? "last" : "first") })

// Add group by if non-aggregate
if (isAggr && exprUtils.getExprAggrStatus(order.expr) !== "aggregate") {
query.groupBy.push(colKeys.length + index + 1)
query.groupBy!.push(colKeys.length + index + 1)
}
})
}
Expand Down

0 comments on commit b411b61

Please sign in to comment.