oak-db 2.1.1 → 2.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/lib/MySQL/store.d.ts +4 -1
- package/lib/MySQL/store.js +30 -3
- package/lib/MySQL/translator.d.ts +1 -1
- package/lib/MySQL/translator.js +4 -1
- package/lib/sqlTranslator.d.ts +2 -1
- package/lib/sqlTranslator.js +110 -11
- package/package.json +3 -3
package/lib/MySQL/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityDict, DeduceCreateSingleOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateOption, OperationResult, TxnOption, StorageSchema, DeduceCreateMultipleOperation, SelectOption } from 'oak-domain/lib/types';
|
|
1
|
+
import { EntityDict, DeduceCreateSingleOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateOption, OperationResult, TxnOption, StorageSchema, DeduceCreateMultipleOperation, SelectOption, AggregationResult } from 'oak-domain/lib/types';
|
|
2
2
|
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
|
3
3
|
import { CascadeStore } from 'oak-domain/lib/store/CascadeStore';
|
|
4
4
|
import { MySQLConfiguration } from './types/Configuration';
|
|
@@ -7,11 +7,14 @@ import { MySqlTranslator, MySqlSelectOption, MysqlOperateOption } from './transl
|
|
|
7
7
|
import { AsyncContext, AsyncRowStore } from 'oak-domain/lib/store/AsyncRowStore';
|
|
8
8
|
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
|
|
9
9
|
export declare class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends CascadeStore<ED> implements AsyncRowStore<ED, Cxt> {
|
|
10
|
+
protected aggregateSync<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): AggregationResult<ED[T]['Schema']>;
|
|
10
11
|
protected selectAbjointRow<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context: SyncContext<ED>, option: OP): Partial<ED[T]['Schema']>[];
|
|
11
12
|
protected updateAbjointRow<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: SyncContext<ED>, option: OP): number;
|
|
12
13
|
connector: MySqlConnector;
|
|
13
14
|
translator: MySqlTranslator<ED>;
|
|
14
15
|
constructor(storageSchema: StorageSchema<ED>, configuration: MySQLConfiguration);
|
|
16
|
+
protected aggregateAsync<T extends keyof ED, OP extends SelectOption, Cxt extends AsyncContext<ED>>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): Promise<AggregationResult<ED[T]['Schema']>>;
|
|
17
|
+
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): Promise<AggregationResult<ED[T]['Schema']>>;
|
|
15
18
|
protected supportManyToOneJoin(): boolean;
|
|
16
19
|
protected supportMultipleCreate(): boolean;
|
|
17
20
|
private formResult;
|
package/lib/MySQL/store.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MysqlStore = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var selection_1 = require("oak-domain/lib/store/selection");
|
|
5
6
|
var CascadeStore_1 = require("oak-domain/lib/store/CascadeStore");
|
|
6
7
|
var connector_1 = require("./connector");
|
|
7
8
|
var translator_1 = require("./translator");
|
|
@@ -28,12 +29,33 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
28
29
|
_this.translator = new translator_1.MySqlTranslator(storageSchema);
|
|
29
30
|
return _this;
|
|
30
31
|
}
|
|
32
|
+
MysqlStore.prototype.aggregateSync = function (entity, aggregation, context, option) {
|
|
33
|
+
throw new Error('MySQL store不支持同步取数据,不应该跑到这儿');
|
|
34
|
+
};
|
|
31
35
|
MysqlStore.prototype.selectAbjointRow = function (entity, selection, context, option) {
|
|
32
36
|
throw new Error('MySQL store不支持同步取数据,不应该跑到这儿');
|
|
33
37
|
};
|
|
34
38
|
MysqlStore.prototype.updateAbjointRow = function (entity, operation, context, option) {
|
|
35
39
|
throw new Error('MySQL store不支持同步更新数据,不应该跑到这儿');
|
|
36
40
|
};
|
|
41
|
+
MysqlStore.prototype.aggregateAsync = function (entity, aggregation, context, option) {
|
|
42
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var sql, result;
|
|
44
|
+
return tslib_1.__generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
sql = this.translator.translateAggregate(entity, aggregation, option);
|
|
48
|
+
return [4 /*yield*/, this.connector.exec(sql, context.getCurrentTxnId())];
|
|
49
|
+
case 1:
|
|
50
|
+
result = _a.sent();
|
|
51
|
+
return [2 /*return*/, this.formResult(entity, result)];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
MysqlStore.prototype.aggregate = function (entity, aggregation, context, option) {
|
|
57
|
+
return this.aggregateAsync(entity, aggregation, context, option);
|
|
58
|
+
};
|
|
37
59
|
MysqlStore.prototype.supportManyToOneJoin = function () {
|
|
38
60
|
return true;
|
|
39
61
|
};
|
|
@@ -54,7 +76,10 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
54
76
|
r[attrHead] = {};
|
|
55
77
|
}
|
|
56
78
|
var rel = (0, relation_1.judgeRelation)(schema, entity2, attrHead);
|
|
57
|
-
if (rel ===
|
|
79
|
+
if (rel === 0) {
|
|
80
|
+
resolveAttribute(entity2, r[attrHead], attrTail, value);
|
|
81
|
+
}
|
|
82
|
+
else if (rel === 2) {
|
|
58
83
|
resolveAttribute(attrHead, r[attrHead], attrTail, value);
|
|
59
84
|
}
|
|
60
85
|
else {
|
|
@@ -133,7 +158,7 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
133
158
|
}
|
|
134
159
|
}
|
|
135
160
|
function removeNullObjects(r, e) {
|
|
136
|
-
|
|
161
|
+
// assert(r.id && typeof r.id === 'string', `对象${<string>e}取数据时发现id为非法值${r.id},rowId是${r.id}`)
|
|
137
162
|
for (var attr in r) {
|
|
138
163
|
var rel = (0, relation_1.judgeRelation)(schema, e, attr);
|
|
139
164
|
if (rel === 2) {
|
|
@@ -270,7 +295,9 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
270
295
|
var result;
|
|
271
296
|
return tslib_1.__generator(this, function (_a) {
|
|
272
297
|
switch (_a.label) {
|
|
273
|
-
case 0:
|
|
298
|
+
case 0:
|
|
299
|
+
(0, selection_1.reinforceSelection)(this.storageSchema, entity, selection);
|
|
300
|
+
return [4 /*yield*/, this.cascadeSelectAsync(entity, selection, context, option)];
|
|
274
301
|
case 1:
|
|
275
302
|
result = _a.sent();
|
|
276
303
|
return [2 /*return*/, result];
|
|
@@ -98,7 +98,7 @@ export declare class MySqlTranslator<ED extends EntityDict> extends SqlTranslato
|
|
|
98
98
|
}): string[];
|
|
99
99
|
private translateFnName;
|
|
100
100
|
protected translateExpression<T extends keyof ED>(alias: string, expression: RefOrExpression<keyof ED[T]["OpSchema"]>, refDict: Record<string, string>): string;
|
|
101
|
-
protected populateSelectStmt<T extends keyof ED>(projectionText: string, fromText: string,
|
|
101
|
+
protected populateSelectStmt<T extends keyof ED>(projectionText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, groupByText?: string, indexFrom?: number, count?: number, option?: MySqlSelectOption): string;
|
|
102
102
|
protected populateUpdateStmt(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: MysqlOperateOption): string;
|
|
103
103
|
protected populateRemoveStmt(removeText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: MysqlOperateOption): string;
|
|
104
104
|
}
|
package/lib/MySQL/translator.js
CHANGED
|
@@ -537,7 +537,7 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
537
537
|
};
|
|
538
538
|
return translateInner(expression);
|
|
539
539
|
};
|
|
540
|
-
MySqlTranslator.prototype.populateSelectStmt = function (projectionText, fromText,
|
|
540
|
+
MySqlTranslator.prototype.populateSelectStmt = function (projectionText, fromText, aliasDict, filterText, sorterText, groupByText, indexFrom, count, option) {
|
|
541
541
|
// todo hint of use index
|
|
542
542
|
var sql = "select ".concat(projectionText, " from ").concat(fromText);
|
|
543
543
|
if (filterText) {
|
|
@@ -546,6 +546,9 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
546
546
|
if (sorterText) {
|
|
547
547
|
sql += " order by ".concat(sorterText);
|
|
548
548
|
}
|
|
549
|
+
if (groupByText) {
|
|
550
|
+
sql += " group by ".concat(groupByText);
|
|
551
|
+
}
|
|
549
552
|
if (typeof indexFrom === 'number') {
|
|
550
553
|
(0, assert_1.default)(typeof count === 'number');
|
|
551
554
|
sql += " limit ".concat(indexFrom, ", ").concat(count);
|
package/lib/sqlTranslator.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare abstract class SqlTranslator<ED extends EntityDict> {
|
|
|
15
15
|
abstract translateCreateEntity<T extends keyof ED>(entity: T, option: {
|
|
16
16
|
replace?: boolean;
|
|
17
17
|
}): string[];
|
|
18
|
-
protected abstract populateSelectStmt<T extends keyof ED, OP extends SqlSelectOption>(projectionText: string, fromText: string,
|
|
18
|
+
protected abstract populateSelectStmt<T extends keyof ED, OP extends SqlSelectOption>(projectionText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, groupByText?: string, indexFrom?: number, count?: number, option?: OP, selection?: ED[T]['Selection'], aggregation?: ED[T]['Aggregation']): string;
|
|
19
19
|
protected abstract populateUpdateStmt<OP extends SqlOperateOption>(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: OP): string;
|
|
20
20
|
protected abstract populateRemoveStmt<OP extends SqlOperateOption>(removeText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: OP): string;
|
|
21
21
|
protected abstract translateExpression<T extends keyof ED>(alias: string, expression: RefOrExpression<keyof ED[T]['OpSchema']>, refDict: Record<string, string>): string;
|
|
@@ -43,6 +43,7 @@ export declare abstract class SqlTranslator<ED extends EntityDict> {
|
|
|
43
43
|
private translateProjection;
|
|
44
44
|
private translateSelectInner;
|
|
45
45
|
translateSelect<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
|
|
46
|
+
translateAggregate<T extends keyof ED, OP extends SqlSelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): string;
|
|
46
47
|
translateCount<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option?: OP): string;
|
|
47
48
|
translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string;
|
|
48
49
|
translateUpdate<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Update'], option?: OP): string;
|
package/lib/sqlTranslator.js
CHANGED
|
@@ -163,7 +163,7 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
163
163
|
*/
|
|
164
164
|
SqlTranslator.prototype.analyzeJoin = function (entity, _a, initialNumber) {
|
|
165
165
|
var _this = this;
|
|
166
|
-
var projection = _a.projection, filter = _a.filter, sorter = _a.sorter,
|
|
166
|
+
var projection = _a.projection, filter = _a.filter, sorter = _a.sorter, aggregation = _a.aggregation;
|
|
167
167
|
var schema = this.schema;
|
|
168
168
|
var number = initialNumber || 1;
|
|
169
169
|
var projectionRefAlias = {};
|
|
@@ -366,7 +366,7 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
366
366
|
}
|
|
367
367
|
});
|
|
368
368
|
if (node['#id']) {
|
|
369
|
-
(0, assert_1.default)(!projectionRefAlias[node['#id']]);
|
|
369
|
+
(0, assert_1.default)(!projectionRefAlias[node['#id']], "projection\u4E0A\u6709\u91CD\u590D\u7684#id\u5B9A\u4E49\u300C".concat(node['#id'], "\u300D"));
|
|
370
370
|
(0, lodash_1.assign)(projectionRefAlias, (_b = {},
|
|
371
371
|
_b[node['#id']] = alias,
|
|
372
372
|
_b));
|
|
@@ -375,6 +375,16 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
375
375
|
if (projection) {
|
|
376
376
|
analyzeProjectionNode({ node: projection, path: './', entityName: entity, alias: alias });
|
|
377
377
|
}
|
|
378
|
+
else if (aggregation) {
|
|
379
|
+
for (var k in aggregation) {
|
|
380
|
+
analyzeProjectionNode({
|
|
381
|
+
node: aggregation[k],
|
|
382
|
+
path: './',
|
|
383
|
+
entityName: entity,
|
|
384
|
+
alias: alias,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
378
388
|
return {
|
|
379
389
|
aliasDict: aliasDict,
|
|
380
390
|
from: from,
|
|
@@ -625,9 +635,10 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
625
635
|
});
|
|
626
636
|
return sortText;
|
|
627
637
|
};
|
|
628
|
-
SqlTranslator.prototype.translateProjection = function (entity, projection, aliasDict, projectionRefAlias) {
|
|
638
|
+
SqlTranslator.prototype.translateProjection = function (entity, projection, aliasDict, projectionRefAlias, commonPrefix, disableAs) {
|
|
629
639
|
var _this = this;
|
|
630
640
|
var schema = this.schema;
|
|
641
|
+
var as = '';
|
|
631
642
|
var translateInner = function (entity2, projection2, path) {
|
|
632
643
|
var alias = aliasDict[path];
|
|
633
644
|
var attributes = schema[entity2].attributes;
|
|
@@ -641,9 +652,21 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
641
652
|
return [1, 2].includes(rel) || typeof rel === 'string';
|
|
642
653
|
});
|
|
643
654
|
attrs.forEach(function (attr, idx) {
|
|
655
|
+
var prefix2 = commonPrefix ? "".concat(commonPrefix, ".").concat(prefix) : prefix;
|
|
644
656
|
if (attr.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
|
|
645
657
|
var exprText = _this.translateExpression(alias, projection2[attr], projectionRefAlias);
|
|
646
|
-
|
|
658
|
+
if (disableAs) {
|
|
659
|
+
projText += " ".concat(exprText);
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
projText += " ".concat(exprText, " as `").concat(prefix2).concat(attr, "`");
|
|
663
|
+
if (!as) {
|
|
664
|
+
as = "`".concat(prefix2).concat(attr, "`");
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
as += ", `".concat(prefix2).concat(attr, "`");
|
|
668
|
+
}
|
|
669
|
+
}
|
|
647
670
|
}
|
|
648
671
|
else {
|
|
649
672
|
var rel = (0, relation_1.judgeRelation)(_this.schema, entity2, attr);
|
|
@@ -656,11 +679,33 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
656
679
|
else if (rel === 1) {
|
|
657
680
|
var type = attributes[attr].type;
|
|
658
681
|
if (projection2[attr] === 1) {
|
|
659
|
-
|
|
682
|
+
if (disableAs) {
|
|
683
|
+
projText += " ".concat(_this.translateAttrProjection(type, alias, attr));
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
projText += " ".concat(_this.translateAttrProjection(type, alias, attr), " as `").concat(prefix2).concat(attr, "`");
|
|
687
|
+
if (!as) {
|
|
688
|
+
as = "`".concat(prefix2).concat(attr, "`");
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
as += ", `".concat(prefix2).concat(attr, "`");
|
|
692
|
+
}
|
|
693
|
+
}
|
|
660
694
|
}
|
|
661
695
|
else {
|
|
662
696
|
(0, assert_1.default)(typeof projection2 === 'string');
|
|
663
|
-
|
|
697
|
+
if (disableAs) {
|
|
698
|
+
projText += " ".concat(_this.translateAttrProjection(type, alias, attr));
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
projText += " ".concat(_this.translateAttrProjection(type, alias, attr), " as `").concat(prefix2).concat(projection2[attr], "`");
|
|
702
|
+
if (!as) {
|
|
703
|
+
as = "`".concat(prefix2).concat(projection2[attr], "`");
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
as += "`".concat(prefix2).concat(projection2[attr], "`");
|
|
707
|
+
}
|
|
708
|
+
}
|
|
664
709
|
}
|
|
665
710
|
}
|
|
666
711
|
}
|
|
@@ -670,7 +715,10 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
670
715
|
});
|
|
671
716
|
return projText;
|
|
672
717
|
};
|
|
673
|
-
return
|
|
718
|
+
return {
|
|
719
|
+
projText: translateInner(entity, projection, './'),
|
|
720
|
+
as: as,
|
|
721
|
+
};
|
|
674
722
|
};
|
|
675
723
|
SqlTranslator.prototype.translateSelectInner = function (entity, selection, initialNumber, refAlias, option) {
|
|
676
724
|
var data = selection.data, filter = selection.filter, sorter = selection.sorter, indexFrom = selection.indexFrom, count = selection.count;
|
|
@@ -681,11 +729,11 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
681
729
|
}, initialNumber), fromText = _a.from, aliasDict = _a.aliasDict, projectionRefAlias = _a.projectionRefAlias, extraWhere = _a.extraWhere, filterRefAlias = _a.filterRefAlias, currentNumber = _a.currentNumber;
|
|
682
730
|
(0, assert_1.default)((0, lodash_1.intersection)((0, lodash_1.keys)(refAlias), (0, lodash_1.keys)(filterRefAlias)).length === 0, 'filter中的#node结点定义有重复');
|
|
683
731
|
(0, lodash_1.assign)(refAlias, filterRefAlias);
|
|
684
|
-
var projText = this.translateProjection(entity, data, aliasDict, projectionRefAlias);
|
|
732
|
+
var projText = this.translateProjection(entity, data, aliasDict, projectionRefAlias).projText;
|
|
685
733
|
var _b = this.translateFilter(entity, selection, aliasDict, refAlias, currentNumber, extraWhere, option), filterText = _b.stmt, currentNumber2 = _b.currentNumber;
|
|
686
734
|
var sorterText = sorter && this.translateSorter(entity, sorter, aliasDict);
|
|
687
735
|
return {
|
|
688
|
-
stmt: this.populateSelectStmt(projText, fromText,
|
|
736
|
+
stmt: this.populateSelectStmt(projText, fromText, aliasDict, filterText, sorterText, undefined, indexFrom, count, option, selection),
|
|
689
737
|
currentNumber: currentNumber2,
|
|
690
738
|
};
|
|
691
739
|
};
|
|
@@ -693,6 +741,57 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
693
741
|
var stmt = this.translateSelectInner(entity, selection, 1, {}, option).stmt;
|
|
694
742
|
return stmt;
|
|
695
743
|
};
|
|
744
|
+
SqlTranslator.prototype.translateAggregate = function (entity, aggregation, option) {
|
|
745
|
+
var data = aggregation.data, filter = aggregation.filter, sorter = aggregation.sorter, indexFrom = aggregation.indexFrom, count = aggregation.count;
|
|
746
|
+
var _a = this.analyzeJoin(entity, {
|
|
747
|
+
aggregation: data,
|
|
748
|
+
filter: filter,
|
|
749
|
+
sorter: sorter,
|
|
750
|
+
}, 1), fromText = _a.from, aliasDict = _a.aliasDict, projectionRefAlias = _a.projectionRefAlias, extraWhere = _a.extraWhere, filterRefAlias = _a.filterRefAlias, currentNumber = _a.currentNumber;
|
|
751
|
+
var projText = '';
|
|
752
|
+
var groupByText = '';
|
|
753
|
+
for (var k in data) {
|
|
754
|
+
if (k === '#aggr') {
|
|
755
|
+
var _b = this.translateProjection(entity, data[k], aliasDict, projectionRefAlias, '#data'), projSubText = _b.projText, as = _b.as;
|
|
756
|
+
if (!projText) {
|
|
757
|
+
projText = projSubText;
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
projText += ", ".concat(projSubText);
|
|
761
|
+
}
|
|
762
|
+
groupByText = as;
|
|
763
|
+
}
|
|
764
|
+
else {
|
|
765
|
+
var projSubText = this.translateProjection(entity, data[k], aliasDict, projectionRefAlias, undefined, true).projText;
|
|
766
|
+
var projSubText2 = '';
|
|
767
|
+
if (k.startsWith('#max')) {
|
|
768
|
+
projSubText2 = "max(".concat(projSubText, ") as `").concat(k, "`");
|
|
769
|
+
}
|
|
770
|
+
else if (k.startsWith('#min')) {
|
|
771
|
+
projSubText2 = "min(".concat(projSubText, ") as `").concat(k, "`");
|
|
772
|
+
}
|
|
773
|
+
else if (k.startsWith('#count')) {
|
|
774
|
+
projSubText2 = "count(".concat(projSubText, ") as `").concat(k, "`");
|
|
775
|
+
}
|
|
776
|
+
else if (k.startsWith('#sum')) {
|
|
777
|
+
projSubText2 = "sum(".concat(projSubText, ") as `").concat(k, "`");
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
(0, assert_1.default)(k.startsWith('#avg'));
|
|
781
|
+
projSubText2 = "avg(".concat(projSubText, ") as `").concat(k, "`");
|
|
782
|
+
}
|
|
783
|
+
if (!projText) {
|
|
784
|
+
projText = projSubText2;
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
projText += ", ".concat(projSubText2);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
var filterText = this.translateFilter(entity, aggregation, aliasDict, {}, currentNumber, extraWhere, option).stmt;
|
|
792
|
+
var sorterText = sorter && this.translateSorter(entity, sorter, aliasDict);
|
|
793
|
+
return this.populateSelectStmt(projText, fromText, aliasDict, filterText, sorterText, groupByText, indexFrom, count, option, undefined, aggregation);
|
|
794
|
+
};
|
|
696
795
|
SqlTranslator.prototype.translateCount = function (entity, selection, option) {
|
|
697
796
|
var filter = selection.filter, count = selection.count;
|
|
698
797
|
var _a = this.analyzeJoin(entity, {
|
|
@@ -701,10 +800,10 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
701
800
|
var projText = 'count(1) cnt';
|
|
702
801
|
var filterText = this.translateFilter(entity, selection, aliasDict, filterRefAlias, currentNumber, extraWhere, option).stmt;
|
|
703
802
|
if (count) {
|
|
704
|
-
var subQuerySql = this.populateSelectStmt('1', fromText, Object.assign({}, selection, { indexFrom: 0, count: count })
|
|
803
|
+
var subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, Object.assign({}, selection, { indexFrom: 0, count: count }));
|
|
705
804
|
return "select count(1) cnt from (".concat(subQuerySql, ") __tmp");
|
|
706
805
|
}
|
|
707
|
-
return this.populateSelectStmt(projText, fromText,
|
|
806
|
+
return this.populateSelectStmt(projText, fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, selection);
|
|
708
807
|
};
|
|
709
808
|
SqlTranslator.prototype.translateRemove = function (entity, operation, option) {
|
|
710
809
|
var filter = operation.filter, sorter = operation.sorter, indexFrom = operation.indexFrom, count = operation.count;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-db",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "oak-db",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"lodash": "^4.17.21",
|
|
19
19
|
"mysql": "^2.18.1",
|
|
20
20
|
"mysql2": "^2.3.3",
|
|
21
|
-
"oak-domain": "^2.
|
|
21
|
+
"oak-domain": "^2.3.0",
|
|
22
22
|
"uuid": "^8.3.2"
|
|
23
23
|
},
|
|
24
24
|
"license": "ISC",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@types/node": "^17.0.42",
|
|
30
30
|
"@types/uuid": "^8.3.4",
|
|
31
31
|
"mocha": "^10.0.0",
|
|
32
|
-
"oak-general-business": "^2.
|
|
32
|
+
"oak-general-business": "^2.3.0",
|
|
33
33
|
"ts-node": "~10.9.1",
|
|
34
34
|
"tslib": "^2.4.0",
|
|
35
35
|
"typescript": "~4.7.4"
|