flowerbi 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/QueryColumn.d.ts +19 -12
- package/dist/QueryColumn.js +43 -15
- package/dist/QueryColumn.js.map +1 -1
- package/dist/QueryJson.d.ts +8 -0
- package/dist/executeQuery.js +4 -2
- package/dist/executeQuery.js.map +1 -1
- package/dist/executeQuery.test.js +18 -6
- package/dist/executeQuery.test.js.map +1 -1
- package/dist/queryModel.d.ts +17 -0
- package/package.json +1 -1
- package/src/QueryColumn.ts +26 -17
- package/src/QueryJson.ts +8 -0
- package/src/executeQuery.test.ts +18 -6
- package/src/executeQuery.ts +4 -2
- package/src/queryModel.ts +17 -0
package/dist/QueryColumn.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FilterValue, FilterJson, AggregationJson, OrderingJson } from "./QueryJson";
|
|
1
|
+
import { FilterValue, AggregationType, FilterJson, AggregationJson, OrderingJson } from "./QueryJson";
|
|
2
2
|
/**
|
|
3
3
|
* A column from the schema, with a name and a data type. A whole schema of
|
|
4
4
|
* such declared columns can be auto-generated using the CLI.
|
|
@@ -9,22 +9,12 @@ export declare class QueryColumn<T extends FilterValue> {
|
|
|
9
9
|
* @param name The name, of the form `table.column`.
|
|
10
10
|
*/
|
|
11
11
|
constructor(name: string);
|
|
12
|
-
|
|
12
|
+
protected aggregation(aggregationType: AggregationType, filters?: FilterJson[]): AggregationJson;
|
|
13
13
|
/**
|
|
14
14
|
* Aggregates the column by counting values.
|
|
15
15
|
* @param filters Optional filters to apply.
|
|
16
16
|
*/
|
|
17
17
|
count(filters?: FilterJson[]): AggregationJson;
|
|
18
|
-
/**
|
|
19
|
-
* Aggregates the column by summing values.
|
|
20
|
-
* @param filters Optional filters to apply.
|
|
21
|
-
*/
|
|
22
|
-
sum(filters?: FilterJson[]): AggregationJson;
|
|
23
|
-
/**
|
|
24
|
-
* Aggregates the column by averaging values.
|
|
25
|
-
* @param filters Optional filters to apply.
|
|
26
|
-
*/
|
|
27
|
-
avg(filters?: FilterJson[]): AggregationJson;
|
|
28
18
|
/**
|
|
29
19
|
* Aggregates the column by selecting the minimum value.
|
|
30
20
|
* @param filters Optional filters to apply.
|
|
@@ -77,3 +67,20 @@ export declare class QueryColumn<T extends FilterValue> {
|
|
|
77
67
|
*/
|
|
78
68
|
in(value: T extends number | string ? T[] : never): FilterJson;
|
|
79
69
|
}
|
|
70
|
+
export declare class NumericQueryColumn extends QueryColumn<number> {
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/**
|
|
73
|
+
* @param name The name, of the form `table.column`.
|
|
74
|
+
*/
|
|
75
|
+
constructor(name: string);
|
|
76
|
+
/**
|
|
77
|
+
* Aggregates the column by summing values.
|
|
78
|
+
* @param filters Optional filters to apply.
|
|
79
|
+
*/
|
|
80
|
+
sum(filters?: FilterJson[]): AggregationJson;
|
|
81
|
+
/**
|
|
82
|
+
* Aggregates the column by averaging values.
|
|
83
|
+
* @param filters Optional filters to apply.
|
|
84
|
+
*/
|
|
85
|
+
avg(filters?: FilterJson[]): AggregationJson;
|
|
86
|
+
}
|
package/dist/QueryColumn.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryColumn = void 0;
|
|
18
|
+
exports.NumericQueryColumn = exports.QueryColumn = void 0;
|
|
4
19
|
/**
|
|
5
20
|
* A column from the schema, with a name and a data type. A whole schema of
|
|
6
21
|
* such declared columns can be auto-generated using the CLI.
|
|
@@ -26,20 +41,6 @@ var QueryColumn = /** @class */ (function () {
|
|
|
26
41
|
QueryColumn.prototype.count = function (filters) {
|
|
27
42
|
return this.aggregation("Count", filters);
|
|
28
43
|
};
|
|
29
|
-
/**
|
|
30
|
-
* Aggregates the column by summing values.
|
|
31
|
-
* @param filters Optional filters to apply.
|
|
32
|
-
*/
|
|
33
|
-
QueryColumn.prototype.sum = function (filters) {
|
|
34
|
-
return this.aggregation("Sum", filters);
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Aggregates the column by averaging values.
|
|
38
|
-
* @param filters Optional filters to apply.
|
|
39
|
-
*/
|
|
40
|
-
QueryColumn.prototype.avg = function (filters) {
|
|
41
|
-
return this.aggregation("Avg", filters);
|
|
42
|
-
};
|
|
43
44
|
/**
|
|
44
45
|
* Aggregates the column by selecting the minimum value.
|
|
45
46
|
* @param filters Optional filters to apply.
|
|
@@ -126,4 +127,31 @@ var QueryColumn = /** @class */ (function () {
|
|
|
126
127
|
return QueryColumn;
|
|
127
128
|
}());
|
|
128
129
|
exports.QueryColumn = QueryColumn;
|
|
130
|
+
var NumericQueryColumn = /** @class */ (function (_super) {
|
|
131
|
+
__extends(NumericQueryColumn, _super);
|
|
132
|
+
/**
|
|
133
|
+
* @param name The name, of the form `table.column`.
|
|
134
|
+
*/
|
|
135
|
+
function NumericQueryColumn(name) {
|
|
136
|
+
var _this = _super.call(this, name) || this;
|
|
137
|
+
_this.name = name;
|
|
138
|
+
return _this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Aggregates the column by summing values.
|
|
142
|
+
* @param filters Optional filters to apply.
|
|
143
|
+
*/
|
|
144
|
+
NumericQueryColumn.prototype.sum = function (filters) {
|
|
145
|
+
return this.aggregation("Sum", filters);
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Aggregates the column by averaging values.
|
|
149
|
+
* @param filters Optional filters to apply.
|
|
150
|
+
*/
|
|
151
|
+
NumericQueryColumn.prototype.avg = function (filters) {
|
|
152
|
+
return this.aggregation("Avg", filters);
|
|
153
|
+
};
|
|
154
|
+
return NumericQueryColumn;
|
|
155
|
+
}(QueryColumn));
|
|
156
|
+
exports.NumericQueryColumn = NumericQueryColumn;
|
|
129
157
|
//# sourceMappingURL=QueryColumn.js.map
|
package/dist/QueryColumn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryColumn.js","sourceRoot":"","sources":["../src/QueryColumn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryColumn.js","sourceRoot":"","sources":["../src/QueryColumn.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA;;;GAGG;AACH;IACI;;OAEG;IACH,qBAA4B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAElC,iCAAW,GAArB,UAAsB,eAAgC,EAAE,OAAsB;QAC1E,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,QAAQ,EAAE,eAAe;YACzB,OAAO,SAAA;SACV,CAAC;IACN,CAAC;IAED;;;OAGG;IACH,2BAAK,GAAL,UAAM,OAAsB;QACxB,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,yBAAG,GAAH,UAAI,OAAsB;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,yB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IACpC,CAAC;IAED;;;OAGG;IACH,wBAAE,GAAF,UAAG,KAA8C;QAC7C,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,QAAQ,EAAE,IAAI;YACd,KAAK,OAAA;SACR,CAAC;IACN,CAAC;IACL,kBAAC;AAAD,CAAC,AApHD,IAoHC;AApHY,kCAAW;AAsHxB;IAAwC,sCAAmB;IACvD;;OAEG;IACH,4BAA4B,IAAY;QAAxC,YACI,kBAAM,IAAI,CAAC,SACd;QAF2B,UAAI,GAAJ,IAAI,CAAQ;;IAExC,CAAC;IAED;;;OAGG;IACH,gCAAG,GAAH,UAAI,OAAsB;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,gCAAG,GAAH,UAAI,OAAsB;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IACL,yBAAC;AAAD,CAAC,AAvBD,CAAwC,WAAW,GAuBlD;AAvBY,gDAAkB"}
|
package/dist/QueryJson.d.ts
CHANGED
package/dist/executeQuery.js
CHANGED
|
@@ -8,7 +8,7 @@ var queryModel_1 = require("./queryModel");
|
|
|
8
8
|
* @param query
|
|
9
9
|
*/
|
|
10
10
|
function jsonifyQuery(query) {
|
|
11
|
-
var select = query.select, filters = query.filters, orderBy = query.orderBy, totals = query.totals, take = query.take, skip = query.skip;
|
|
11
|
+
var select = query.select, filters = query.filters, orderBy = query.orderBy, totals = query.totals, take = query.take, skip = query.skip, comment = query.comment, allowDuplicates = query.allowDuplicates;
|
|
12
12
|
return {
|
|
13
13
|
select: (0, queryModel_1.getColumnPropsOnly)(select).map(function (key) { return select[key].name; }),
|
|
14
14
|
aggregations: (0, queryModel_1.getAggregatePropsOnly)(select).map(function (key) { return select[key]; }),
|
|
@@ -16,7 +16,9 @@ function jsonifyQuery(query) {
|
|
|
16
16
|
orderBy: orderBy !== null && orderBy !== void 0 ? orderBy : [],
|
|
17
17
|
totals: totals !== null && totals !== void 0 ? totals : false,
|
|
18
18
|
skip: skip !== null && skip !== void 0 ? skip : 0,
|
|
19
|
-
take: take !== null && take !== void 0 ? take : 100
|
|
19
|
+
take: take !== null && take !== void 0 ? take : 100,
|
|
20
|
+
comment: comment,
|
|
21
|
+
allowDuplicates: allowDuplicates
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
24
|
exports.jsonifyQuery = jsonifyQuery;
|
package/dist/executeQuery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeQuery.js","sourceRoot":"","sources":["../src/executeQuery.ts"],"names":[],"mappings":";;;AAAA,2CAAuI;AAiDvI;;;;GAIG;AACH,SAAgB,YAAY,CAAwB,KAAe;IACvD,IAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"executeQuery.js","sourceRoot":"","sources":["../src/executeQuery.ts"],"names":[],"mappings":";;;AAAA,2CAAuI;AAiDvI;;;;GAIG;AACH,SAAgB,YAAY,CAAwB,KAAe;IACvD,IAAA,MAAM,GAAqE,KAAK,OAA1E,EAAE,OAAO,GAA4D,KAAK,QAAjE,EAAE,OAAO,GAAmD,KAAK,QAAxD,EAAE,MAAM,GAA2C,KAAK,OAAhD,EAAE,IAAI,GAAqC,KAAK,KAA1C,EAAE,IAAI,GAA+B,KAAK,KAApC,EAAE,OAAO,GAAsB,KAAK,QAA3B,EAAE,eAAe,GAAK,KAAK,gBAAV,CAAW;IAEzF,OAAO;QACH,MAAM,EAAE,IAAA,+BAAkB,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAC,MAAM,CAAC,GAAG,CAAwB,CAAC,IAAI,EAAxC,CAAwC,CAAC;QACvF,YAAY,EAAE,IAAA,kCAAqB,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,MAAM,CAAC,GAAG,CAAoB,EAA9B,CAA8B,CAAC;QACt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B,EAAE;QAA5C,IAAM,GAAG,SAAA;QACV,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;KACxC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAbD,wDAaC;AAoBD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC7B,MAAS,EACT,MAAuB;IAGvB,OAAO;QACH,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,EAA5B,CAA4B,CAAC;QAC9D,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;KACzE,CAAC;AACN,CAAC;AATD,8CASC"}
|
|
@@ -28,7 +28,9 @@ test("jsonifies mixed columns", function () {
|
|
|
28
28
|
orderBy: [],
|
|
29
29
|
skip: 0,
|
|
30
30
|
take: 100,
|
|
31
|
-
totals: false
|
|
31
|
+
totals: false,
|
|
32
|
+
allowDuplicates: undefined,
|
|
33
|
+
comment: undefined,
|
|
32
34
|
});
|
|
33
35
|
});
|
|
34
36
|
test("jsonifies select", function () {
|
|
@@ -43,7 +45,9 @@ test("jsonifies select", function () {
|
|
|
43
45
|
orderBy: [],
|
|
44
46
|
skip: 0,
|
|
45
47
|
take: 100,
|
|
46
|
-
totals: false
|
|
48
|
+
totals: false,
|
|
49
|
+
allowDuplicates: undefined,
|
|
50
|
+
comment: undefined,
|
|
47
51
|
});
|
|
48
52
|
});
|
|
49
53
|
test("jsonifies params", function () {
|
|
@@ -51,7 +55,9 @@ test("jsonifies params", function () {
|
|
|
51
55
|
select: {},
|
|
52
56
|
skip: 3,
|
|
53
57
|
take: 42,
|
|
54
|
-
totals: true
|
|
58
|
+
totals: true,
|
|
59
|
+
allowDuplicates: true,
|
|
60
|
+
comment: "a comment",
|
|
55
61
|
})).toStrictEqual({
|
|
56
62
|
select: [],
|
|
57
63
|
aggregations: [],
|
|
@@ -59,7 +65,9 @@ test("jsonifies params", function () {
|
|
|
59
65
|
orderBy: [],
|
|
60
66
|
skip: 3,
|
|
61
67
|
take: 42,
|
|
62
|
-
totals: true
|
|
68
|
+
totals: true,
|
|
69
|
+
allowDuplicates: true,
|
|
70
|
+
comment: "a comment",
|
|
63
71
|
});
|
|
64
72
|
});
|
|
65
73
|
test("jsonifies filters", function () {
|
|
@@ -91,7 +99,9 @@ test("jsonifies filters", function () {
|
|
|
91
99
|
orderBy: [],
|
|
92
100
|
skip: 0,
|
|
93
101
|
take: 100,
|
|
94
|
-
totals: false
|
|
102
|
+
totals: false,
|
|
103
|
+
allowDuplicates: undefined,
|
|
104
|
+
comment: undefined,
|
|
95
105
|
});
|
|
96
106
|
});
|
|
97
107
|
test("jsonifies orderBy", function () {
|
|
@@ -110,7 +120,9 @@ test("jsonifies orderBy", function () {
|
|
|
110
120
|
}],
|
|
111
121
|
skip: 0,
|
|
112
122
|
take: 100,
|
|
113
|
-
totals: false
|
|
123
|
+
totals: false,
|
|
124
|
+
allowDuplicates: undefined,
|
|
125
|
+
comment: undefined,
|
|
114
126
|
});
|
|
115
127
|
});
|
|
116
128
|
//# sourceMappingURL=executeQuery.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeQuery.test.js","sourceRoot":"","sources":["../src/executeQuery.test.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAC9C,6CAA4C;AAE/B,QAAA,QAAQ,GAAG;IACpB,EAAE,EAAE,IAAI,yBAAW,CAAS,aAAa,CAAC;IAC1C,YAAY,EAAE,IAAI,yBAAW,CAAS,uBAAuB,CAAC;CACjE,CAAC;AAEW,QAAA,GAAG,GAAG;IACf,EAAE,EAAE,IAAI,yBAAW,CAAS,QAAQ,CAAC;IACrC,UAAU,EAAE,IAAI,yBAAW,CAAS,gBAAgB,CAAC;CACxD,CAAC;AAEF,IAAI,CAAC,yBAAyB,EAAE;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,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/dist/queryModel.d.ts
CHANGED
|
@@ -130,4 +130,21 @@ export interface Query<S extends QuerySelect> {
|
|
|
130
130
|
* Number of result records to return.
|
|
131
131
|
*/
|
|
132
132
|
take?: number;
|
|
133
|
+
/**
|
|
134
|
+
* A string to insert in a comment at the start of the generated SQL.
|
|
135
|
+
*
|
|
136
|
+
* This will be aggressively processed to remove the danger of injection
|
|
137
|
+
* attacks, so anything other than alpha, numeric, new line or CR
|
|
138
|
+
* characters will be replaced with space.
|
|
139
|
+
*/
|
|
140
|
+
comment?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Only applicable if the query specifies only ordinary columns, no
|
|
143
|
+
* aggregations. If true, no GROUP BY clause is added to the SQL, so if
|
|
144
|
+
* multiple results have the same values they will appear repeatedly in
|
|
145
|
+
* the output. This can greatly reduce the work required by the SQL
|
|
146
|
+
* engine, and so should be specified if duplicate rows are tolerable or
|
|
147
|
+
* are known to be impossible.
|
|
148
|
+
*/
|
|
149
|
+
allowDuplicates?: boolean;
|
|
133
150
|
}
|
package/package.json
CHANGED
package/src/QueryColumn.ts
CHANGED
|
@@ -10,7 +10,7 @@ export class QueryColumn<T extends FilterValue> {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor(public readonly name: string) {}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
protected aggregation(aggregationType: AggregationType, filters?: FilterJson[]): AggregationJson {
|
|
14
14
|
return {
|
|
15
15
|
column: this.name,
|
|
16
16
|
function: aggregationType,
|
|
@@ -26,22 +26,6 @@ export class QueryColumn<T extends FilterValue> {
|
|
|
26
26
|
return this.aggregation("Count", filters);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
* Aggregates the column by summing values.
|
|
31
|
-
* @param filters Optional filters to apply.
|
|
32
|
-
*/
|
|
33
|
-
sum(filters?: FilterJson[]) {
|
|
34
|
-
return this.aggregation("Sum", filters);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Aggregates the column by averaging values.
|
|
39
|
-
* @param filters Optional filters to apply.
|
|
40
|
-
*/
|
|
41
|
-
avg(filters?: FilterJson[]) {
|
|
42
|
-
return this.aggregation("Avg", filters);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
29
|
/**
|
|
46
30
|
* Aggregates the column by selecting the minimum value.
|
|
47
31
|
* @param filters Optional filters to apply.
|
|
@@ -137,3 +121,28 @@ export class QueryColumn<T extends FilterValue> {
|
|
|
137
121
|
};
|
|
138
122
|
}
|
|
139
123
|
}
|
|
124
|
+
|
|
125
|
+
export class NumericQueryColumn extends QueryColumn<number> {
|
|
126
|
+
/**
|
|
127
|
+
* @param name The name, of the form `table.column`.
|
|
128
|
+
*/
|
|
129
|
+
constructor(public readonly name: string) {
|
|
130
|
+
super(name);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Aggregates the column by summing values.
|
|
135
|
+
* @param filters Optional filters to apply.
|
|
136
|
+
*/
|
|
137
|
+
sum(filters?: FilterJson[]) {
|
|
138
|
+
return this.aggregation("Sum", filters);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Aggregates the column by averaging values.
|
|
143
|
+
* @param filters Optional filters to apply.
|
|
144
|
+
*/
|
|
145
|
+
avg(filters?: FilterJson[]) {
|
|
146
|
+
return this.aggregation("Avg", filters);
|
|
147
|
+
}
|
|
148
|
+
}
|
package/src/QueryJson.ts
CHANGED
package/src/executeQuery.test.ts
CHANGED
|
@@ -28,7 +28,9 @@ test("jsonifies mixed columns", () => {
|
|
|
28
28
|
orderBy: [],
|
|
29
29
|
skip: 0,
|
|
30
30
|
take: 100,
|
|
31
|
-
totals: false
|
|
31
|
+
totals: false,
|
|
32
|
+
allowDuplicates: undefined,
|
|
33
|
+
comment: undefined,
|
|
32
34
|
});
|
|
33
35
|
});
|
|
34
36
|
|
|
@@ -44,7 +46,9 @@ test("jsonifies select", () => {
|
|
|
44
46
|
orderBy: [],
|
|
45
47
|
skip: 0,
|
|
46
48
|
take: 100,
|
|
47
|
-
totals: false
|
|
49
|
+
totals: false,
|
|
50
|
+
allowDuplicates: undefined,
|
|
51
|
+
comment: undefined,
|
|
48
52
|
});
|
|
49
53
|
});
|
|
50
54
|
|
|
@@ -53,7 +57,9 @@ test("jsonifies params", () => {
|
|
|
53
57
|
select: {},
|
|
54
58
|
skip: 3,
|
|
55
59
|
take: 42,
|
|
56
|
-
totals: true
|
|
60
|
+
totals: true,
|
|
61
|
+
allowDuplicates: true,
|
|
62
|
+
comment: "a comment",
|
|
57
63
|
})).toStrictEqual({
|
|
58
64
|
select: [],
|
|
59
65
|
aggregations: [],
|
|
@@ -61,7 +67,9 @@ test("jsonifies params", () => {
|
|
|
61
67
|
orderBy: [],
|
|
62
68
|
skip: 3,
|
|
63
69
|
take: 42,
|
|
64
|
-
totals: true
|
|
70
|
+
totals: true,
|
|
71
|
+
allowDuplicates: true,
|
|
72
|
+
comment: "a comment",
|
|
65
73
|
});
|
|
66
74
|
});
|
|
67
75
|
|
|
@@ -95,7 +103,9 @@ test("jsonifies filters", () => {
|
|
|
95
103
|
orderBy: [],
|
|
96
104
|
skip: 0,
|
|
97
105
|
take: 100,
|
|
98
|
-
totals: false
|
|
106
|
+
totals: false,
|
|
107
|
+
allowDuplicates: undefined,
|
|
108
|
+
comment: undefined,
|
|
99
109
|
});
|
|
100
110
|
});
|
|
101
111
|
|
|
@@ -115,6 +125,8 @@ test("jsonifies orderBy", () => {
|
|
|
115
125
|
}],
|
|
116
126
|
skip: 0,
|
|
117
127
|
take: 100,
|
|
118
|
-
totals: false
|
|
128
|
+
totals: false,
|
|
129
|
+
allowDuplicates: undefined,
|
|
130
|
+
comment: undefined,
|
|
119
131
|
});
|
|
120
132
|
});
|
package/src/executeQuery.ts
CHANGED
|
@@ -53,7 +53,7 @@ export type QueryFetch = (queryJson: QueryJson) => Promise<QueryResultJson>;
|
|
|
53
53
|
* @param query
|
|
54
54
|
*/
|
|
55
55
|
export function jsonifyQuery<S extends QuerySelect>(query: Query<S>): QueryJson {
|
|
56
|
-
const { select, filters, orderBy, totals, take, skip } = query;
|
|
56
|
+
const { select, filters, orderBy, totals, take, skip, comment, allowDuplicates } = query;
|
|
57
57
|
|
|
58
58
|
return {
|
|
59
59
|
select: getColumnPropsOnly(select).map(key => (select[key] as QueryColumn<never>).name),
|
|
@@ -62,7 +62,9 @@ export function jsonifyQuery<S extends QuerySelect>(query: Query<S>): QueryJson
|
|
|
62
62
|
orderBy: orderBy ?? [],
|
|
63
63
|
totals: totals ?? false,
|
|
64
64
|
skip: skip ?? 0,
|
|
65
|
-
take: take ?? 100
|
|
65
|
+
take: take ?? 100,
|
|
66
|
+
comment,
|
|
67
|
+
allowDuplicates
|
|
66
68
|
};
|
|
67
69
|
}
|
|
68
70
|
|
package/src/queryModel.ts
CHANGED
|
@@ -156,4 +156,21 @@ export interface Query<S extends QuerySelect> {
|
|
|
156
156
|
* Number of result records to return.
|
|
157
157
|
*/
|
|
158
158
|
take?: number;
|
|
159
|
+
/**
|
|
160
|
+
* A string to insert in a comment at the start of the generated SQL.
|
|
161
|
+
*
|
|
162
|
+
* This will be aggressively processed to remove the danger of injection
|
|
163
|
+
* attacks, so anything other than alpha, numeric, new line or CR
|
|
164
|
+
* characters will be replaced with space.
|
|
165
|
+
*/
|
|
166
|
+
comment?: string;
|
|
167
|
+
/**
|
|
168
|
+
* Only applicable if the query specifies only ordinary columns, no
|
|
169
|
+
* aggregations. If true, no GROUP BY clause is added to the SQL, so if
|
|
170
|
+
* multiple results have the same values they will appear repeatedly in
|
|
171
|
+
* the output. This can greatly reduce the work required by the SQL
|
|
172
|
+
* engine, and so should be specified if duplicate rows are tolerable or
|
|
173
|
+
* are known to be impossible.
|
|
174
|
+
*/
|
|
175
|
+
allowDuplicates?: boolean;
|
|
159
176
|
}
|