oak-db 3.3.4 → 3.3.5
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.d.ts +15 -15
- package/lib/MySQL/store.d.ts +1 -1
- package/lib/MySQL/store.js +8 -8
- package/lib/MySQL/translator.js +10 -10
- package/lib/sqlTranslator.js +982 -982
- package/package.json +2 -2
package/lib/MySQL/connector.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import mysql, { Pool } from 'mysql2/promise';
|
|
2
|
-
import { TxnOption } from 'oak-domain/lib/types';
|
|
3
|
-
import { MySQLConfiguration } from './types/Configuration';
|
|
4
|
-
export declare class MySqlConnector {
|
|
5
|
-
pool: Pool;
|
|
6
|
-
configuration: MySQLConfiguration;
|
|
7
|
-
txnDict: Record<string, mysql.PoolConnection>;
|
|
8
|
-
constructor(configuration: MySQLConfiguration);
|
|
9
|
-
connect(): void;
|
|
10
|
-
disconnect(): Promise<void>;
|
|
11
|
-
startTransaction(option?: TxnOption): Promise<string>;
|
|
12
|
-
exec(sql: string, txn?: string): Promise<
|
|
13
|
-
commitTransaction(txn: string): Promise<void>;
|
|
14
|
-
rollbackTransaction(txn: string): Promise<void>;
|
|
15
|
-
}
|
|
1
|
+
import mysql, { Pool } from 'mysql2/promise';
|
|
2
|
+
import { TxnOption } from 'oak-domain/lib/types';
|
|
3
|
+
import { MySQLConfiguration } from './types/Configuration';
|
|
4
|
+
export declare class MySqlConnector {
|
|
5
|
+
pool: Pool;
|
|
6
|
+
configuration: MySQLConfiguration;
|
|
7
|
+
txnDict: Record<string, mysql.PoolConnection>;
|
|
8
|
+
constructor(configuration: MySQLConfiguration);
|
|
9
|
+
connect(): void;
|
|
10
|
+
disconnect(): Promise<void>;
|
|
11
|
+
startTransaction(option?: TxnOption): Promise<string>;
|
|
12
|
+
exec(sql: string, txn?: string): Promise<[mysql.RowDataPacket[] | mysql.RowDataPacket[][] | mysql.OkPacket | mysql.OkPacket[] | mysql.ResultSetHeader, mysql.FieldPacket[]]>;
|
|
13
|
+
commitTransaction(txn: string): Promise<void>;
|
|
14
|
+
rollbackTransaction(txn: string): Promise<void>;
|
|
15
|
+
}
|
package/lib/MySQL/store.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt exte
|
|
|
12
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
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
14
|
protected updateAbjointRow<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: SyncContext<ED>, option: OP): number;
|
|
15
|
-
exec(script: string, txnId?: string): Promise<
|
|
15
|
+
exec(script: string, txnId?: string): Promise<void>;
|
|
16
16
|
connector: MySqlConnector;
|
|
17
17
|
translator: MySqlTranslator<ED>;
|
|
18
18
|
constructor(storageSchema: StorageSchema<ED>, configuration: MySQLConfiguration);
|
package/lib/MySQL/store.js
CHANGED
|
@@ -33,8 +33,8 @@ class MysqlStore extends CascadeStore_1.CascadeStore {
|
|
|
33
33
|
updateAbjointRow(entity, operation, context, option) {
|
|
34
34
|
throw new Error('MySQL store不支持同步更新数据,不应该跑到这儿');
|
|
35
35
|
}
|
|
36
|
-
exec(script, txnId) {
|
|
37
|
-
|
|
36
|
+
async exec(script, txnId) {
|
|
37
|
+
await this.connector.exec(script, txnId);
|
|
38
38
|
}
|
|
39
39
|
connector;
|
|
40
40
|
translator;
|
|
@@ -240,21 +240,21 @@ class MysqlStore extends CascadeStore_1.CascadeStore {
|
|
|
240
240
|
case 'create': {
|
|
241
241
|
const { data } = operation;
|
|
242
242
|
const sql = translator.translateInsert(entity, data instanceof Array ? data : [data]);
|
|
243
|
-
await connector.exec(sql, txn);
|
|
244
|
-
return
|
|
243
|
+
const result = await connector.exec(sql, txn);
|
|
244
|
+
return result[0].affectedRows;
|
|
245
245
|
}
|
|
246
246
|
case 'remove': {
|
|
247
247
|
const sql = translator.translateRemove(entity, operation, option);
|
|
248
|
-
await connector.exec(sql, txn);
|
|
248
|
+
const result = await connector.exec(sql, txn);
|
|
249
249
|
// todo 这里对sorter和indexfrom/count的支持不完整
|
|
250
|
-
return
|
|
250
|
+
return result[0].changedRows;
|
|
251
251
|
}
|
|
252
252
|
default: {
|
|
253
253
|
(0, assert_1.default)(!['select', 'download', 'stat'].includes(action));
|
|
254
254
|
const sql = translator.translateUpdate(entity, operation, option);
|
|
255
|
-
await connector.exec(sql, txn);
|
|
255
|
+
const result = await connector.exec(sql, txn);
|
|
256
256
|
// todo 这里对sorter和indexfrom/count的支持不完整
|
|
257
|
-
return
|
|
257
|
+
return result[0].changedRows;
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
}
|
package/lib/MySQL/translator.js
CHANGED
|
@@ -119,21 +119,21 @@ class MySqlTranslator extends sqlTranslator_1.SqlTranslator {
|
|
|
119
119
|
// numeric types
|
|
120
120
|
"bit",
|
|
121
121
|
"int",
|
|
122
|
-
"integer",
|
|
122
|
+
"integer",
|
|
123
123
|
"tinyint",
|
|
124
124
|
"smallint",
|
|
125
125
|
"mediumint",
|
|
126
126
|
"bigint",
|
|
127
127
|
"float",
|
|
128
128
|
"double",
|
|
129
|
-
"double precision",
|
|
130
|
-
"real",
|
|
129
|
+
"double precision",
|
|
130
|
+
"real",
|
|
131
131
|
"decimal",
|
|
132
|
-
"dec",
|
|
133
|
-
"numeric",
|
|
134
|
-
"fixed",
|
|
135
|
-
"bool",
|
|
136
|
-
"boolean",
|
|
132
|
+
"dec",
|
|
133
|
+
"numeric",
|
|
134
|
+
"fixed",
|
|
135
|
+
"bool",
|
|
136
|
+
"boolean",
|
|
137
137
|
// date and time types
|
|
138
138
|
"date",
|
|
139
139
|
"datetime",
|
|
@@ -142,10 +142,10 @@ class MySqlTranslator extends sqlTranslator_1.SqlTranslator {
|
|
|
142
142
|
"year",
|
|
143
143
|
// string types
|
|
144
144
|
"char",
|
|
145
|
-
"nchar",
|
|
145
|
+
"nchar",
|
|
146
146
|
"national char",
|
|
147
147
|
"varchar",
|
|
148
|
-
"nvarchar",
|
|
148
|
+
"nvarchar",
|
|
149
149
|
"national varchar",
|
|
150
150
|
"blob",
|
|
151
151
|
"text",
|