oak-db 3.3.12 → 3.3.14
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/connector.js +9 -14
- package/lib/MySQL/store.d.ts +5 -15
- package/lib/MySQL/store.js +11 -2
- package/lib/MySQL/translator.js +22 -11
- package/lib/PostgreSQL/connector.d.ts +0 -4
- package/lib/PostgreSQL/connector.js +29 -58
- package/lib/PostgreSQL/store.d.ts +16 -1
- package/lib/PostgreSQL/store.js +247 -7
- package/lib/PostgreSQL/translator.d.ts +39 -7
- package/lib/PostgreSQL/translator.js +480 -225
- package/lib/sqlTranslator.d.ts +5 -1
- package/lib/sqlTranslator.js +18 -8
- package/lib/types/dbStore.d.ts +27 -2
- package/package.json +2 -2
package/lib/sqlTranslator.d.ts
CHANGED
|
@@ -53,7 +53,11 @@ export declare abstract class SqlTranslator<ED extends EntityDict & BaseEntityDi
|
|
|
53
53
|
};
|
|
54
54
|
private translateSorter;
|
|
55
55
|
private translateProjection;
|
|
56
|
-
|
|
56
|
+
protected translateSelectInner<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], initialNumber: number, refAlias: Record<string, [string, keyof ED]>, option?: OP): {
|
|
57
|
+
filterStmt: string;
|
|
58
|
+
stmt: string;
|
|
59
|
+
currentNumber: number;
|
|
60
|
+
};
|
|
57
61
|
translateSelect<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
|
|
58
62
|
translateWhere<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
|
|
59
63
|
translateAggregate<T extends keyof ED, OP extends SqlSelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): string;
|
package/lib/sqlTranslator.js
CHANGED
|
@@ -72,6 +72,8 @@ class SqlTranslator {
|
|
|
72
72
|
name: `${entity}_trigger_uuid_auto_create`,
|
|
73
73
|
attributes: [{
|
|
74
74
|
name: types_1.TriggerUuidAttribute,
|
|
75
|
+
}, {
|
|
76
|
+
name: types_1.DeleteAtAttribute,
|
|
75
77
|
}]
|
|
76
78
|
},
|
|
77
79
|
];
|
|
@@ -84,7 +86,7 @@ class SqlTranslator {
|
|
|
84
86
|
attributes: [{
|
|
85
87
|
name: attr,
|
|
86
88
|
}, {
|
|
87
|
-
name:
|
|
89
|
+
name: types_1.DeleteAtAttribute,
|
|
88
90
|
}]
|
|
89
91
|
});
|
|
90
92
|
}
|
|
@@ -100,7 +102,7 @@ class SqlTranslator {
|
|
|
100
102
|
}, {
|
|
101
103
|
name: 'entityId',
|
|
102
104
|
}, {
|
|
103
|
-
name:
|
|
105
|
+
name: types_1.DeleteAtAttribute,
|
|
104
106
|
}]
|
|
105
107
|
});
|
|
106
108
|
}
|
|
@@ -113,7 +115,7 @@ class SqlTranslator {
|
|
|
113
115
|
attributes: [{
|
|
114
116
|
name: attr,
|
|
115
117
|
}, {
|
|
116
|
-
name:
|
|
118
|
+
name: types_1.DeleteAtAttribute,
|
|
117
119
|
}]
|
|
118
120
|
});
|
|
119
121
|
}
|
|
@@ -129,7 +131,7 @@ class SqlTranslator {
|
|
|
129
131
|
}, {
|
|
130
132
|
name: 'expiresAt',
|
|
131
133
|
}, {
|
|
132
|
-
name:
|
|
134
|
+
name: types_1.DeleteAtAttribute,
|
|
133
135
|
}]
|
|
134
136
|
});
|
|
135
137
|
}
|
|
@@ -562,10 +564,10 @@ class SqlTranslator {
|
|
|
562
564
|
translateFilter(entity, filter, aliasDict, filterRefAlias, initialNumber, option) {
|
|
563
565
|
const { schema } = this;
|
|
564
566
|
let currentNumber = initialNumber;
|
|
565
|
-
const translateInner = (entity2, path, filter2,
|
|
567
|
+
const translateInner = (entity2, path, filter2, skipDeletePhy) => {
|
|
566
568
|
const alias = aliasDict[path];
|
|
567
569
|
const { attributes } = schema[entity2];
|
|
568
|
-
let whereText =
|
|
570
|
+
let whereText = skipDeletePhy ? '' : this.getDefaultSelectFilter(alias, option);
|
|
569
571
|
if (filter2) {
|
|
570
572
|
const attrs = Object.keys(filter2).filter(ele => !ele.startsWith('#'));
|
|
571
573
|
attrs.forEach((attr) => {
|
|
@@ -580,7 +582,7 @@ class SqlTranslator {
|
|
|
580
582
|
case '$xor': {
|
|
581
583
|
const logicQueries = filter2[attr];
|
|
582
584
|
logicQueries.forEach((logicQuery, index) => {
|
|
583
|
-
const sql = translateInner(entity2, path, logicQuery,
|
|
585
|
+
const sql = translateInner(entity2, path, logicQuery, true); // 只要传个值就行了,应该无所谓
|
|
584
586
|
if (sql) {
|
|
585
587
|
whereText += ` (${sql})`;
|
|
586
588
|
if (index < logicQueries.length - 1) {
|
|
@@ -593,7 +595,7 @@ class SqlTranslator {
|
|
|
593
595
|
default: {
|
|
594
596
|
(0, assert_1.default)(attr === '$not');
|
|
595
597
|
const logicQuery = filter2[attr];
|
|
596
|
-
const sql = translateInner(entity2, path, logicQuery,
|
|
598
|
+
const sql = translateInner(entity2, path, logicQuery, true); // 只要传个值就行了,应该无所谓
|
|
597
599
|
if (sql) {
|
|
598
600
|
whereText += ` not (${sql})`;
|
|
599
601
|
break;
|
|
@@ -963,6 +965,10 @@ class SqlTranslator {
|
|
|
963
965
|
const { data, filter, sorter, indexFrom, count } = operation;
|
|
964
966
|
(0, assert_1.default)(!sorter, '当前remove不支持sorter行为');
|
|
965
967
|
const { aliasDict, filterRefAlias, from: fromText, currentNumber } = this.analyzeJoin(entity, { filter, sorter });
|
|
968
|
+
// 对于limit,如果有indexForm则一定有count
|
|
969
|
+
if (typeof indexFrom === 'number') {
|
|
970
|
+
(0, assert_1.default)(typeof count === 'number' && count > 0);
|
|
971
|
+
}
|
|
966
972
|
const alias = aliasDict['./'];
|
|
967
973
|
// 这里原来includeDeleted传的是true,不知道原因,但不合理
|
|
968
974
|
const { stmt: filterText } = this.translateFilter(entity, filter, aliasDict, filterRefAlias, currentNumber, { includedDeleted: option?.includedDeleted });
|
|
@@ -990,6 +996,10 @@ class SqlTranslator {
|
|
|
990
996
|
const { filter, sorter, indexFrom, count, data } = operation;
|
|
991
997
|
(0, assert_1.default)(!sorter, '当前update不支持sorter行为');
|
|
992
998
|
const { aliasDict, filterRefAlias, from: fromText, currentNumber } = this.analyzeJoin(entity, { filter, sorter });
|
|
999
|
+
// 对于limit,如果有indexForm则一定有count
|
|
1000
|
+
if (typeof indexFrom === 'number') {
|
|
1001
|
+
(0, assert_1.default)(typeof count === 'number' && count > 0);
|
|
1002
|
+
}
|
|
993
1003
|
const alias = aliasDict['./'];
|
|
994
1004
|
let updateText = '';
|
|
995
1005
|
for (const attr in data) {
|
package/lib/types/dbStore.d.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
import { EntityDict } from
|
|
1
|
+
import { Attribute, EntityDict, Index, OperateOption, OperationResult, StorageSchema, TxnOption } from 'oak-domain/lib/types';
|
|
2
|
+
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
|
2
3
|
import { AsyncContext, AsyncRowStore } from "oak-domain/lib/store/AsyncRowStore";
|
|
3
4
|
import { CreateEntityOption } from "./Translator";
|
|
4
|
-
|
|
5
|
+
import { AggregationResult, SelectOption } from "oak-domain/lib/types";
|
|
6
|
+
export type Plan = {
|
|
7
|
+
newTables: Record<string, {
|
|
8
|
+
attributes: Record<string, Attribute>;
|
|
9
|
+
}>;
|
|
10
|
+
newIndexes: Record<string, Index<any>[]>;
|
|
11
|
+
updatedTables: Record<string, {
|
|
12
|
+
attributes: Record<string, Attribute & {
|
|
13
|
+
isNew: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
16
|
+
updatedIndexes: Record<string, Index<any>[]>;
|
|
17
|
+
};
|
|
18
|
+
export interface DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends AsyncRowStore<ED, Cxt> {
|
|
19
|
+
checkRelationAsync<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, operation: Omit<ED[T]['Operation'] | ED[T]['Selection'], 'id'>, context: Cxt): Promise<void>;
|
|
5
20
|
connect: () => Promise<void>;
|
|
6
21
|
disconnect: () => Promise<void>;
|
|
7
22
|
initialize(options: CreateEntityOption): Promise<void>;
|
|
23
|
+
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): Promise<AggregationResult<ED[T]['Schema']>>;
|
|
24
|
+
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OperateOption): Promise<OperationResult<ED>>;
|
|
25
|
+
select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: SelectOption): Promise<Partial<ED[T]['Schema']>[]>;
|
|
26
|
+
count<T extends keyof ED>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: SelectOption): Promise<number>;
|
|
27
|
+
begin(option?: TxnOption): Promise<string>;
|
|
28
|
+
commit(txnId: string): Promise<void>;
|
|
29
|
+
rollback(txnId: string): Promise<void>;
|
|
30
|
+
readSchema(): Promise<StorageSchema<ED>>;
|
|
31
|
+
makeUpgradePlan(): Promise<Plan>;
|
|
32
|
+
diffSchema(schemaOld: StorageSchema<any>, schemaNew: StorageSchema<any>): Plan;
|
|
8
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-db",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.14",
|
|
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": "^5.1.
|
|
21
|
+
"oak-domain": "^5.1.36",
|
|
22
22
|
"pg": "^8.16.3",
|
|
23
23
|
"uuid": "^8.3.2"
|
|
24
24
|
},
|