oak-db 3.2.1 → 3.3.1
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 +5 -6
- package/lib/MySQL/store.d.ts +11 -11
- package/lib/MySQL/store.js +3 -3
- package/lib/MySQL/translator.js +7 -3
- package/lib/MySQL/types/Configuration.d.ts +1 -0
- package/lib/MySQL/types/Configuration.js +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -4
- package/lib/sqlTranslator.js +982 -982
- package/package.json +3 -3
package/lib/MySQL/connector.js
CHANGED
|
@@ -20,6 +20,7 @@ class MySqlConnector {
|
|
|
20
20
|
return this.pool.end();
|
|
21
21
|
}
|
|
22
22
|
async startTransaction(option) {
|
|
23
|
+
// 防止用户配置connection可复用
|
|
23
24
|
const startInner = async () => {
|
|
24
25
|
const connection = await this.pool.getConnection();
|
|
25
26
|
// 分配出来的connection不能被别的事务占据
|
|
@@ -32,7 +33,7 @@ class MySqlConnector {
|
|
|
32
33
|
}
|
|
33
34
|
await connection.beginTransaction();
|
|
34
35
|
const id = (0, uuid_1.v4)();
|
|
35
|
-
console.log('start_txn', id, connection.threadId);
|
|
36
|
+
// console.log('start_txn', id, connection.threadId);
|
|
36
37
|
this.txnDict[id] = connection;
|
|
37
38
|
if (option?.isolationLevel) {
|
|
38
39
|
await connection.query(`SET TRANSACTION ISOLATION LEVEL ${option.isolationLevel};`);
|
|
@@ -58,18 +59,16 @@ class MySqlConnector {
|
|
|
58
59
|
}
|
|
59
60
|
async commitTransaction(txn) {
|
|
60
61
|
const connection = this.txnDict[txn];
|
|
61
|
-
|
|
62
|
-
console.log('qiguai!');
|
|
63
|
-
}
|
|
62
|
+
(0, assert_1.default)(connection);
|
|
64
63
|
delete this.txnDict[txn];
|
|
65
|
-
console.log('commit_txn', txn, connection.threadId);
|
|
64
|
+
// console.log('commit_txn', txn, connection.threadId);
|
|
66
65
|
await connection.commit();
|
|
67
66
|
connection.release();
|
|
68
67
|
}
|
|
69
68
|
async rollbackTransaction(txn) {
|
|
70
69
|
const connection = this.txnDict[txn];
|
|
71
70
|
(0, assert_1.default)(connection);
|
|
72
|
-
console.log('rollback_txn', txn, connection.threadId);
|
|
71
|
+
// console.log('rollback_txn', txn, connection.threadId);
|
|
73
72
|
await connection.rollback();
|
|
74
73
|
delete this.txnDict[txn];
|
|
75
74
|
connection.release();
|
package/lib/MySQL/store.d.ts
CHANGED
|
@@ -4,28 +4,28 @@ import { CascadeStore } from 'oak-domain/lib/store/CascadeStore';
|
|
|
4
4
|
import { MySQLConfiguration } from './types/Configuration';
|
|
5
5
|
import { MySqlConnector } from './connector';
|
|
6
6
|
import { MySqlTranslator, MySqlSelectOption, MysqlOperateOption } from './translator';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { AsyncContext, AsyncRowStore } from 'oak-domain/lib/store/AsyncRowStore';
|
|
8
|
+
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
|
|
9
9
|
import { CreateEntityOption } from '../types/Translator';
|
|
10
|
-
export declare class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|
11
|
-
protected countAbjointRow<T extends keyof ED, OP extends SelectOption, Cxt extends
|
|
12
|
-
protected aggregateAbjointRowSync<T extends keyof ED, OP extends SelectOption, Cxt extends
|
|
13
|
-
protected selectAbjointRow<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context:
|
|
14
|
-
protected updateAbjointRow<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context:
|
|
10
|
+
export declare class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends CascadeStore<ED> implements AsyncRowStore<ED, Cxt> {
|
|
11
|
+
protected countAbjointRow<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: OP): number;
|
|
12
|
+
protected aggregateAbjointRowSync<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']>;
|
|
13
|
+
protected selectAbjointRow<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context: SyncContext<ED>, option: OP): Partial<ED[T]['Schema']>[];
|
|
14
|
+
protected updateAbjointRow<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: SyncContext<ED>, option: OP): number;
|
|
15
15
|
exec(script: string, txnId?: string): Promise<any>;
|
|
16
16
|
connector: MySqlConnector;
|
|
17
17
|
translator: MySqlTranslator<ED>;
|
|
18
18
|
constructor(storageSchema: StorageSchema<ED>, configuration: MySQLConfiguration);
|
|
19
|
-
protected aggregateAbjointRowAsync<T extends keyof ED, OP extends SelectOption, Cxt extends
|
|
19
|
+
protected aggregateAbjointRowAsync<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']>>;
|
|
20
20
|
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): Promise<AggregationResult<ED[T]['Schema']>>;
|
|
21
21
|
protected supportManyToOneJoin(): boolean;
|
|
22
22
|
protected supportMultipleCreate(): boolean;
|
|
23
23
|
private formResult;
|
|
24
|
-
protected selectAbjointRowAsync<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context:
|
|
25
|
-
protected updateAbjointRowAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context:
|
|
24
|
+
protected selectAbjointRowAsync<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: AsyncContext<ED>, option?: MySqlSelectOption): Promise<Partial<ED[T]['Schema']>[]>;
|
|
25
|
+
protected updateAbjointRowAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option?: MysqlOperateOption): Promise<number>;
|
|
26
26
|
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OperateOption): Promise<OperationResult<ED>>;
|
|
27
27
|
select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: SelectOption): Promise<Partial<ED[T]['Schema']>[]>;
|
|
28
|
-
protected countAbjointRowAsync<T extends keyof ED>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context:
|
|
28
|
+
protected countAbjointRowAsync<T extends keyof ED>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: AsyncContext<ED>, option: SelectOption): Promise<number>;
|
|
29
29
|
count<T extends keyof ED>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: SelectOption): Promise<number>;
|
|
30
30
|
begin(option?: TxnOption): Promise<string>;
|
|
31
31
|
commit(txnId: string): Promise<void>;
|
package/lib/MySQL/store.js
CHANGED
|
@@ -192,18 +192,18 @@ class MysqlStore extends CascadeStore_1.CascadeStore {
|
|
|
192
192
|
const rel = (0, relation_1.judgeRelation)(schema, e, attr);
|
|
193
193
|
if (rel === 2) {
|
|
194
194
|
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
|
195
|
-
|
|
195
|
+
// assert(schema[e].toModi || r.entity !== attr || r.entityId === r[attr].id, `对象${<string>e}取数据时,发现entityId与连接的对象的主键不一致,rowId是${r.id},其entityId值为${r.entityId},连接的对象的主键为${r[attr].id}`);
|
|
196
196
|
if (r[attr].id === null) {
|
|
197
197
|
(0, assert_1.default)(schema[e].toModi || r.entity !== attr);
|
|
198
198
|
delete r[attr];
|
|
199
199
|
continue;
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
// assert(r.entity === attr, `对象${<string>e}取数据时,发现entity值与连接的外键对象不一致,rowId是${r.id},其entity值为${r.entity},连接的对象为${attr}`);
|
|
202
202
|
removeNullObjects(r[attr], attr);
|
|
203
203
|
}
|
|
204
204
|
else if (typeof rel === 'string') {
|
|
205
205
|
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
|
206
|
-
|
|
206
|
+
// assert(schema[e].toModi || r[`${attr}Id`] === r[attr].id, `对象${<string>e}取数据时,发现其外键与连接的对象的主键不一致,rowId是${r.id},其${attr}Id值为${r[`${attr}Id`]},连接的对象的主键为${r[attr].id}`);
|
|
207
207
|
if (r[attr].id === null) {
|
|
208
208
|
(0, assert_1.default)(schema[e].toModi || r[`${attr}Id`] === null);
|
|
209
209
|
delete r[attr];
|
package/lib/MySQL/translator.js
CHANGED
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
const util_1 = require("util");
|
|
7
7
|
const lodash_1 = require("lodash");
|
|
8
|
+
const types_1 = require("oak-domain/lib/types");
|
|
8
9
|
const sqlTranslator_1 = require("../sqlTranslator");
|
|
9
10
|
const GeoTypes = [
|
|
10
11
|
{
|
|
@@ -920,9 +921,12 @@ class MySqlTranslator extends sqlTranslator_1.SqlTranslator {
|
|
|
920
921
|
}
|
|
921
922
|
return sql;
|
|
922
923
|
}
|
|
923
|
-
|
|
924
|
-
const
|
|
925
|
-
|
|
924
|
+
// 新的remove应该包含$$deleteAt$$的值了
|
|
925
|
+
/* const now = Date.now();
|
|
926
|
+
|
|
927
|
+
const updateText2 = updateText ? `${updateText}, \`${alias}\`.\`$$deleteAt$$\` = '${now}'` : `\`${alias}\`.\`$$deleteAt$$\` = '${now}'`; */
|
|
928
|
+
(0, assert_1.default)(updateText.includes(types_1.DeleteAtAttribute));
|
|
929
|
+
let sql = `update ${fromText} set ${updateText}`;
|
|
926
930
|
if (filterText) {
|
|
927
931
|
sql += ` where ${filterText}`;
|
|
928
932
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './MySQL/store';
|
|
2
|
-
export { MySqlSelectOption, MysqlOperateOption } from './MySQL/translator';
|
|
1
|
+
export * from './MySQL/store';
|
|
2
|
+
export { MySqlSelectOption, MysqlOperateOption } from './MySQL/translator';
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./MySQL/store"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./MySQL/store"), exports);
|