oak-db 3.3.3 → 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.
@@ -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<any>;
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
+ }
@@ -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<any>;
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);
@@ -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
- return this.connector.exec(script, txnId);
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 data instanceof Array ? data.length : 1;
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 1;
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 1;
257
+ return result[0].changedRows;
258
258
  }
259
259
  }
260
260
  }