midway-fatcms 0.0.1-beta.75 → 0.0.1-beta.77

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.
Files changed (48) hide show
  1. package/dist/controller/base/BaseApiController.js +6 -2
  2. package/dist/controller/manage/SystemInfoManageApi.js +2 -0
  3. package/dist/libs/crud-pro/CrudPro.js +3 -0
  4. package/dist/libs/crud-pro/interfaces.d.ts +10 -1
  5. package/dist/libs/crud-pro/models/Transaction.d.ts +21 -2
  6. package/dist/libs/crud-pro/models/Transaction.js +118 -15
  7. package/dist/libs/crud-pro/models/TransactionMySQL.d.ts +11 -20
  8. package/dist/libs/crud-pro/models/TransactionMySQL.js +33 -61
  9. package/dist/libs/crud-pro/models/TransactionPostgres.d.ts +11 -20
  10. package/dist/libs/crud-pro/models/TransactionPostgres.js +39 -60
  11. package/dist/libs/crud-pro/models/TransactionSqlServer.d.ts +1 -26
  12. package/dist/libs/crud-pro/models/TransactionSqlServer.js +42 -73
  13. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +3 -3
  14. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +10 -19
  15. package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +1 -1
  16. package/dist/libs/crud-pro/services/CrudProTableMetaService.js +3 -3
  17. package/dist/libs/crud-pro/utils/CrudMonitor.d.ts +9 -0
  18. package/dist/libs/crud-pro/utils/CrudMonitor.js +12 -0
  19. package/dist/libs/crud-pro/utils/MixinUtils.d.ts +1 -0
  20. package/dist/libs/crud-pro/utils/MixinUtils.js +3 -0
  21. package/dist/libs/crud-pro/utils/sqlConvert/convertMix.d.ts +0 -3
  22. package/dist/libs/crud-pro/utils/sqlConvert/convertMix.js +24 -22
  23. package/dist/models/userSession.d.ts +1 -0
  24. package/dist/models/userSession.js +1 -0
  25. package/dist/schedule/anonymousContext.js +2 -1
  26. package/dist/service/AuthService.js +6 -1
  27. package/package.json +1 -1
  28. package/src/controller/base/BaseApiController.ts +7 -2
  29. package/src/controller/manage/SuperAdminManageApi.ts +6 -6
  30. package/src/controller/manage/SystemInfoManageApi.ts +2 -0
  31. package/src/libs/crud-pro/CrudPro.ts +5 -0
  32. package/src/libs/crud-pro/interfaces.ts +10 -1
  33. package/src/libs/crud-pro/models/Transaction.ts +141 -19
  34. package/src/libs/crud-pro/models/TransactionMySQL.ts +39 -60
  35. package/src/libs/crud-pro/models/TransactionPostgres.ts +49 -61
  36. package/src/libs/crud-pro/models/TransactionSqlServer.ts +52 -77
  37. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +3 -3
  38. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +13 -22
  39. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +3 -3
  40. package/src/libs/crud-pro/utils/CrudMonitor.ts +13 -0
  41. package/src/libs/crud-pro/utils/MixinUtils.ts +3 -0
  42. package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +24 -24
  43. package/src/models/userSession.ts +2 -0
  44. package/src/schedule/anonymousContext.ts +2 -1
  45. package/src/service/AuthService.ts +7 -1
  46. package/dist/libs/crud-pro/utils/sqlConvert/convertPgType.d.ts +0 -2
  47. package/dist/libs/crud-pro/utils/sqlConvert/convertPgType.js +0 -128
  48. package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -127
@@ -1,24 +1,91 @@
1
- import { IConnectionPool, IPoolConnectionClient } from '../interfaces';
1
+ import {IConnectionPool, IPoolConnectionClient, IPoolConnectionQueryResult} from '../interfaces';
2
2
  import { SqlDbType } from './keys';
3
3
  import { TransactionMySQL } from './TransactionMySQL';
4
4
  import { TransactionPostgres } from './TransactionPostgres';
5
5
  import { TransactionSqlServer } from './TransactionSqlServer';
6
6
 
7
+ class TransactionConnection implements IPoolConnectionClient {
8
+ originConnection: IPoolConnectionClient;
9
+ private isFinished: boolean = false;
10
+ private isTxBegan: boolean = false;
11
+ private isTxCommitted: boolean = false;
12
+ private isTxRollback: boolean = false;
13
+ private isReleased: boolean = false;
14
+
15
+ constructor(originConnection: IPoolConnectionClient) {
16
+ this.originConnection = originConnection;
17
+ }
18
+
19
+ async query(sql: string, values: any[]): Promise<IPoolConnectionQueryResult> {
20
+ try {
21
+ return await this.originConnection.query(sql, values);
22
+ } catch (error) {
23
+ console.error('[crud-pro]TransactionConnection',error);
24
+ throw error;
25
+ } finally {
26
+ this.isFinished = true;
27
+ }
28
+ }
29
+
30
+
31
+ async beginTransaction() {
32
+ this.isTxBegan = true;
33
+ await this.originConnection.beginTransaction();
34
+ }
35
+
36
+ async commit() {
37
+ this.isTxCommitted = true;
38
+ await this.originConnection.commit();
39
+ }
40
+
41
+ async rollback() {
42
+ this.isTxRollback = true;
43
+ await this.originConnection.commit();
44
+ }
45
+
46
+ async release() {
47
+ if (this.isReleased) {
48
+ return;
49
+ }
50
+ this.isReleased = true;
51
+ try {
52
+ if (this.isTxBegan && !this.isTxRollback && !this.isTxCommitted) {
53
+ await this.commit();
54
+ }
55
+ await this.originConnection.release();
56
+ } catch (e) {
57
+ console.log('[crud-pro] MySqlConnectionClient release ', e);
58
+ }
59
+ }
60
+
61
+ async releaseOnlyFinished() {
62
+ if (this.isFinished) {
63
+ await this.release();
64
+ }
65
+ }
66
+
67
+ }
68
+
69
+
7
70
  class Transaction {
8
71
  private transactionMySQL: TransactionMySQL = new TransactionMySQL();
9
72
  private transactionPostgres: TransactionPostgres = new TransactionPostgres();
10
73
  private transactionSqlServer: TransactionSqlServer = new TransactionSqlServer();
74
+
75
+ private isBeginTransaction = false;
76
+ private connectionMap: Record<string, TransactionConnection> = {};
77
+ private connectionList: TransactionConnection[] = [];
78
+
79
+
11
80
  private isReleased = false;
12
81
 
13
82
  private getTxObj(pool: IConnectionPool): TransactionMySQL | TransactionPostgres | TransactionSqlServer {
14
83
  if (pool.dbType === SqlDbType.postgres) {
15
84
  return this.transactionPostgres;
16
85
  }
17
-
18
86
  if (pool.dbType === SqlDbType.sqlserver) {
19
87
  return this.transactionSqlServer;
20
88
  }
21
-
22
89
  if (!pool.dbType || pool.dbType === SqlDbType.mysql) {
23
90
  return this.transactionMySQL;
24
91
  }
@@ -29,53 +96,108 @@ class Transaction {
29
96
  * 获取链接对象
30
97
  * @param pool
31
98
  */
32
- public async getTxConnection(pool: IConnectionPool): Promise<IPoolConnectionClient> {
99
+ public async getTxConnection(pool: IConnectionPool): Promise<TransactionConnection> {
33
100
  if (this.isReleased) {
34
- const msg = '[Transaction] getTxConnection error, the txObject is isReleased, please check your code . DB request must be await';
101
+ const msg = '[crud-pro][Transaction] getTxConnection error, the txObject is isReleased, please check your code . DB request must be await';
35
102
  console.error(msg);
36
103
  throw new Error(msg);
37
104
  }
38
105
 
39
- const txObj = this.getTxObj(pool);
40
- return txObj.getTxConnection(pool);
106
+
107
+
108
+ // 尽量复用同一个连接。但是如果并行请求,也允许使用多个链接。
109
+ // 复用一个链接:可以使用事务。
110
+ // 使用多个链接:不能使用事务。
111
+ let connection = this.connectionMap[pool.poolName];
112
+ if (!connection) {
113
+
114
+ const txObj = this.getTxObj(pool);
115
+ const connection0 = await txObj.getTxConnection(pool);
116
+ connection = new TransactionConnection(connection0);
117
+
118
+ this.connectionMap[pool.poolName] = connection;
119
+ this.connectionList.push(connection);
120
+
121
+ // 开启了事务
122
+ if (this.isBeginTransaction) {
123
+ await connection.beginTransaction();
124
+ }
125
+ }
126
+
127
+ return connection;
128
+
41
129
  }
42
130
 
43
131
  /**
44
132
  * 开始事务
45
133
  */
46
134
  public beginTx() {
47
- this.transactionMySQL.beginTx();
48
- this.transactionPostgres.beginTx();
49
- this.transactionSqlServer.beginTx();
135
+ this.isBeginTransaction = true;
50
136
  }
51
137
 
52
138
  /**
53
139
  * 提交事务
54
140
  */
55
141
  public async commitTx() {
56
- await this.transactionMySQL.commitTx();
57
- await this.transactionPostgres.commitTx();
58
- await this.transactionSqlServer.commitTx();
142
+ if (!this.isBeginTransaction) {
143
+ return;
144
+ }
145
+ const connections = this.connectionList;
146
+ for (let i = 0; i < connections.length; i++) {
147
+ const connection = connections[i];
148
+ await connection.commit();
149
+ }
59
150
  }
60
151
 
61
152
  /**
62
153
  * 事务回滚
63
154
  */
64
155
  public async rollbackTx() {
65
- await this.transactionMySQL.rollbackTx();
66
- await this.transactionPostgres.rollbackTx();
67
- await this.transactionSqlServer.rollbackTx();
156
+ if (!this.isBeginTransaction) {
157
+ return;
158
+ }
159
+ const connections = this.connectionList;
160
+ for (let i = 0; i < connections.length; i++) {
161
+ const connection = connections[i];
162
+ await connection.rollback();
163
+ }
68
164
  }
69
165
 
70
166
  /**
71
167
  * 释放连接
72
168
  */
73
169
  public async releaseTx() {
74
- await this.transactionMySQL.releaseTx();
75
- await this.transactionPostgres.releaseTx();
76
- await this.transactionSqlServer.releaseTx();
77
170
  this.isReleased = true;
171
+
172
+ // 不管有没有开启事务,都要释放连接。
173
+ const connections = this.connectionList;
174
+ for (let i = 0; i < connections.length; i++) {
175
+ const connection = connections[i];
176
+ try {
177
+ await connection.releaseOnlyFinished();
178
+ } catch (e) {
179
+ console.error(e);
180
+ }
181
+ }
78
182
  }
183
+
184
+ public async releaseTxOnlyReleased(){
185
+ if (!this.isReleased) {
186
+ return;
187
+ }
188
+
189
+ // 不管有没有开启事务,都要释放连接。
190
+ const connections = this.connectionList;
191
+ for (let i = 0; i < connections.length; i++) {
192
+ const connection = connections[i];
193
+ try {
194
+ await connection.releaseOnlyFinished();
195
+ } catch (e) {
196
+ console.error(e);
197
+ }
198
+ }
199
+ }
200
+
79
201
  }
80
202
 
81
203
  export { Transaction };
@@ -1,78 +1,57 @@
1
1
  import { PoolConnection, Pool } from 'mysql2/promise';
2
- import { IConnectionPool } from '../interfaces';
2
+ import {IConnectionPool, IPoolConnectionClient, IPoolConnectionQueryResult} from '../interfaces';
3
+ import { CrudMonitor } from "@/libs/crud-pro/utils/CrudMonitor";
3
4
 
4
- class TransactionMySQL {
5
- private isBeginTransaction = false;
6
- private connectionMap: Record<string, PoolConnection> = {};
7
5
 
8
- /**
9
- * 获取链接对象
10
- * @param pool
11
- */
12
- public async getTxConnection(pool: IConnectionPool): Promise<PoolConnection> {
13
- let connection = this.connectionMap[pool.poolName];
14
- if (!connection) {
15
- const poolInstance: Pool = pool.poolInstance as any;
16
- connection = await poolInstance.getConnection();
17
- this.connectionMap[pool.poolName] = connection;
18
- // 开启了事务
19
- if (this.isBeginTransaction) {
20
- await connection.beginTransaction();
21
- }
6
+ class MySqlConnectionClient implements IPoolConnectionClient {
7
+ originConnection: PoolConnection;
8
+ constructor(originConnection: PoolConnection) {
9
+ this.originConnection = originConnection;
10
+ CrudMonitor.mysqlGetConnectionCount++;
11
+ }
12
+ async query(sql: string, values: any[]): Promise<IPoolConnectionQueryResult> {
13
+ const res = await this.originConnection.query(sql, values);
14
+ const rows = res[0] as any;
15
+ return {
16
+ rows,
17
+ originRes: res
22
18
  }
23
- return connection;
24
19
  }
25
20
 
26
- /**
27
- * 开始事务
28
- */
29
- public beginTx() {
30
- this.isBeginTransaction = true;
21
+ async beginTransaction() {
22
+ await this.originConnection.beginTransaction();
31
23
  }
32
24
 
33
- /**
34
- * 提交事务
35
- */
36
- public async commitTx() {
37
- if (!this.isBeginTransaction) {
38
- return;
39
- }
40
- const connections = Object.values(this.connectionMap);
41
- for (let i = 0; i < connections.length; i++) {
42
- const connection = connections[i];
43
- await connection.commit();
44
- }
25
+ async commit() {
26
+ await this.originConnection.commit();
45
27
  }
46
28
 
47
- /**
48
- * 事务回滚
49
- */
50
- public async rollbackTx() {
51
- if (!this.isBeginTransaction) {
52
- return;
53
- }
54
- const connections = Object.values(this.connectionMap);
55
- for (let i = 0; i < connections.length; i++) {
56
- const connection = connections[i];
57
- await connection.rollback();
29
+ async rollback() {
30
+ await this.originConnection.commit();
31
+ }
32
+
33
+ async release() {
34
+ try {
35
+ CrudMonitor.mysqlReleaseConnectionCount++;
36
+ await this.originConnection.release();
37
+ } catch (e) {
38
+ console.log('[crud-pro] MySqlConnectionClient release ', e);
58
39
  }
59
40
  }
60
41
 
42
+
43
+ }
44
+
45
+
46
+ class TransactionMySQL {
61
47
  /**
62
- * 释放连接
48
+ * 获取链接对象
49
+ * @param pool
63
50
  */
64
- public async releaseTx() {
65
- // 不管有没有开启事务,都要释放连接。
66
- const connections = Object.values(this.connectionMap);
67
- for (let i = 0; i < connections.length; i++) {
68
- const connection = connections[i];
69
- try {
70
- await connection.release();
71
- } catch (e) {
72
- console.error(e);
73
- }
74
- }
75
- this.connectionMap = {};
51
+ public async getTxConnection(pool: IConnectionPool): Promise<MySqlConnectionClient> {
52
+ const poolInstance: Pool = pool.poolInstance as any;
53
+ const originConnection = await poolInstance.getConnection();
54
+ return new MySqlConnectionClient(originConnection);
76
55
  }
77
56
  }
78
57
 
@@ -1,5 +1,6 @@
1
- import { PoolClient, Pool } from 'pg';
2
- import { IConnectionPool } from '../interfaces';
1
+ import {Pool, PoolClient} from 'pg';
2
+ import {IConnectionPool, IPoolConnectionClient, IPoolConnectionQueryResult} from '../interfaces';
3
+ import { CrudMonitor } from "@/libs/crud-pro/utils/CrudMonitor";
3
4
 
4
5
  async function beginTransaction(connection: PoolClient) {
5
6
  return await connection.query('BEGIN');
@@ -13,78 +14,65 @@ async function rollback(connection: PoolClient) {
13
14
  return await connection.query('ROLLBACK');
14
15
  }
15
16
 
16
- class TransactionPostgres {
17
- private isBeginTransaction = false;
18
- private connectionMap: Record<string, PoolClient> = {};
19
17
 
20
- /**
21
- * 获取链接对象
22
- * @param pool
23
- */
24
- public async getTxConnection(pool: IConnectionPool): Promise<PoolClient> {
25
- let connection = this.connectionMap[pool.poolName];
26
- if (!connection) {
27
- const poolInstance: Pool = pool.poolInstance as any;
28
- connection = await poolInstance.connect();
29
- this.connectionMap[pool.poolName] = connection;
30
- // 开启了事务
31
- if (this.isBeginTransaction) {
32
- await beginTransaction(connection);
33
- }
18
+ class PostgresConnectionClient implements IPoolConnectionClient {
19
+ originConnection: PoolClient;
20
+ constructor(originConnection: PoolClient) {
21
+ this.originConnection = originConnection;
22
+ CrudMonitor.postgresGetConnectionCount++;
23
+ }
24
+ async query(sql: string, values: any[]): Promise<IPoolConnectionQueryResult> {
25
+ const pgClient = this.originConnection;
26
+ const result = await pgClient.query({
27
+ text: sql,
28
+ values: values || [],
29
+ });
30
+ let rows: any[] = [];
31
+ if (result && Array.isArray(result.rows)) {
32
+ rows = result.rows;
33
+ }
34
+
35
+ return {
36
+ rows,
37
+ originRes: result
34
38
  }
35
- return connection;
36
39
  }
37
40
 
38
- /**
39
- * 开始事务
40
- */
41
- public beginTx() {
42
- this.isBeginTransaction = true;
41
+ async beginTransaction() {
42
+ await beginTransaction(this.originConnection);
43
43
  }
44
44
 
45
- /**
46
- * 提交事务
47
- */
48
- public async commitTx() {
49
- if (!this.isBeginTransaction) {
50
- return;
51
- }
52
- const connections = Object.values(this.connectionMap);
53
- for (let i = 0; i < connections.length; i++) {
54
- const connection = connections[i];
55
- await commit(connection);
56
- }
45
+ async commit() {
46
+ await commit(this.originConnection);
57
47
  }
58
48
 
59
- /**
60
- * 事务回滚
61
- */
62
- public async rollbackTx() {
63
- if (!this.isBeginTransaction) {
64
- return;
65
- }
66
- const connections = Object.values(this.connectionMap);
67
- for (let i = 0; i < connections.length; i++) {
68
- const connection = connections[i];
69
- await rollback(connection);
49
+ async rollback() {
50
+ await rollback(this.originConnection);
51
+ }
52
+
53
+
54
+ async release() {
55
+ try {
56
+ CrudMonitor.postgresReleaseConnectionCount++;
57
+ await this.originConnection.release();
58
+ } catch (e) {
59
+ console.log('[crud-pro] PostgresConnectionClient release ', e);
70
60
  }
71
61
  }
72
62
 
63
+ }
64
+
65
+
66
+
67
+ class TransactionPostgres {
73
68
  /**
74
- * 释放连接
69
+ * 获取链接对象
70
+ * @param pool
75
71
  */
76
- public async releaseTx() {
77
- // 不管有没有开启事务,都要释放连接。
78
- const connections = Object.values(this.connectionMap);
79
- for (let i = 0; i < connections.length; i++) {
80
- const connection = connections[i];
81
- try {
82
- await connection.release();
83
- } catch (e) {
84
- console.error(e);
85
- }
86
- }
87
- this.connectionMap = {};
72
+ public async getTxConnection(pool: IConnectionPool): Promise<PostgresConnectionClient> {
73
+ const poolInstance: Pool = pool.poolInstance as any;
74
+ const originConnection = await poolInstance.connect();
75
+ return new PostgresConnectionClient(originConnection);
88
76
  }
89
77
  }
90
78
 
@@ -1,102 +1,77 @@
1
1
  import { ConnectionPool, Request, Transaction } from 'mssql';
2
- import { IConnectionPool, IPoolConnectionClient } from '../interfaces';
2
+ import {IConnectionPool, IPoolConnectionClient, IPoolConnectionQueryResult} from '../interfaces';
3
+ import { CrudMonitor } from "@/libs/crud-pro/utils/CrudMonitor";
4
+ import * as _ from 'lodash';
3
5
 
4
- interface ISqlServerConnection extends IPoolConnectionClient {
5
- originConnection: ConnectionPool;
6
- }
7
6
 
8
- class TransactionSqlServer {
9
- private isBeginTransaction = false;
10
- private connectionMap: Record<string, ISqlServerConnection> = {};
11
- private transactionMap: Record<string, Transaction> = {};
12
7
 
13
- /**
14
- * 获取链接对象
15
- * @param pool
16
- */
17
- public async getTxConnection(pool: IConnectionPool): Promise<ISqlServerConnection> {
18
- let connection = this.connectionMap[pool.poolName];
19
- if (!connection) {
20
- connection = await this.connectAndCreateConnection(pool);
21
- this.connectionMap[pool.poolName] = connection;
22
-
23
- // 开启了事务
24
- if (this.isBeginTransaction) {
25
- await this.beginTransaction(pool.poolName);
8
+ class SqlServerConnectionClient implements IPoolConnectionClient {
9
+ originConnection: ConnectionPool;
10
+ private sqlServerTransaction: Transaction;
11
+ constructor(originConnection: ConnectionPool) {
12
+ this.originConnection = originConnection;
13
+ }
14
+ async query(sql: string, values: any[]): Promise<IPoolConnectionQueryResult> {
15
+ const request = new Request(this.originConnection);
16
+
17
+ if (Array.isArray(values)) {
18
+ for (let i = 0; i < values.length; i++) {
19
+ const index = i + 1;
20
+ const value = values[i];
21
+ request.input(`fatcms_ms${index}`, value);
26
22
  }
27
23
  }
28
- return connection;
29
- }
30
24
 
31
- private async connectAndCreateConnection(pool: IConnectionPool): Promise<ISqlServerConnection> {
32
- const poolInstance: ConnectionPool = pool.poolInstance as any;
33
- const originConnection = await poolInstance.connect();
25
+ const res = await request.query(sql);
26
+ const rows = _.get(res, 'recordsets[0]') || [];
34
27
  return {
35
- originConnection,
36
- query: (sql: string, values: any): Promise<any> => {
37
- const request = new Request(originConnection);
38
- if (Array.isArray(values)) {
39
- for (let i = 0; i < values.length; i++) {
40
- const index = i + 1;
41
- const value = values[i];
42
- request.input(`fatcms_ms${index}`, value);
43
- }
44
- }
45
- return request.query(sql);
46
- },
28
+ rows,
29
+ originRes: res
47
30
  };
48
31
  }
49
32
 
50
- /**
51
- * 开始事务
52
- */
53
- public beginTx() {
54
- this.isBeginTransaction = true;
33
+
34
+
35
+ async beginTransaction() {
36
+ const originConnection: ConnectionPool = this.originConnection;
37
+ const tmpTx = new Transaction(originConnection);
38
+ this.sqlServerTransaction = tmpTx;
39
+ return await tmpTx.begin();
55
40
  }
56
41
 
57
- /**
58
- * 提交事务
59
- */
60
- public async commitTx() {
61
- if (!this.isBeginTransaction) {
62
- return;
63
- }
64
- const transactions = Object.values(this.transactionMap);
65
- for (let i = 0; i < transactions.length; i++) {
66
- const tmpTx = transactions[i];
67
- await tmpTx.commit();
68
- }
42
+ async commit() {
43
+ const tmpTx = this.sqlServerTransaction;
44
+ await tmpTx.commit();
69
45
  }
70
46
 
71
- /**
72
- * 事务回滚
73
- */
74
- public async rollbackTx() {
75
- if (!this.isBeginTransaction) {
76
- return;
77
- }
78
- const transactions = Object.values(this.transactionMap);
79
- for (let i = 0; i < transactions.length; i++) {
80
- const tmpTx = transactions[i];
81
- await tmpTx.rollback();
47
+ async rollback() {
48
+ const tmpTx = this.sqlServerTransaction;
49
+ await tmpTx.rollback();
50
+ }
51
+
52
+
53
+ async release() {
54
+ try {
55
+ CrudMonitor.postgresReleaseConnectionCount++;
56
+ } catch (e) {
57
+ console.log('[crud-pro] SqlServerConnectionClient release ', e);
82
58
  }
83
59
  }
84
60
 
61
+ }
62
+
63
+ class TransactionSqlServer {
64
+
85
65
  /**
86
- * 释放连接
66
+ * 获取链接对象
67
+ * @param pool
87
68
  */
88
- public async releaseTx() {
89
- this.connectionMap = {};
90
- this.transactionMap = {};
69
+ public async getTxConnection(pool: IConnectionPool): Promise<IPoolConnectionClient> {
70
+ const poolInstance: ConnectionPool = pool.poolInstance as any;
71
+ const originConnection = await poolInstance.connect();
72
+ return new SqlServerConnectionClient(originConnection);
91
73
  }
92
74
 
93
- private async beginTransaction(poolName: string) {
94
- const connection = this.connectionMap[poolName];
95
- const originConnection: ConnectionPool = connection.originConnection;
96
- const tmpTx = new Transaction(originConnection);
97
- this.transactionMap[poolName] = tmpTx;
98
- return await tmpTx.begin();
99
- }
100
75
  }
101
76
 
102
77
  export { TransactionSqlServer };
@@ -3,7 +3,7 @@ import { CrudProServiceBase } from './CrudProServiceBase';
3
3
  import { IRequestCfgModel } from '../interfaces';
4
4
  import { MixinUtils } from '../utils/MixinUtils';
5
5
  import { ICurdProServiceHub } from '../models/ServiceHub';
6
- import { pickAndConvertRowsByMix } from '../utils/sqlConvert/convertMix';
6
+ // import { pickAndConvertRowsByMix } from '../utils/sqlConvert/convertMix';
7
7
  import MemoryRefreshCache from '../utils/MemoryRefreshCache';
8
8
 
9
9
  const methodCache = new MemoryRefreshCache();
@@ -57,7 +57,7 @@ class CrudProCachedCfgService extends CrudProServiceBase {
57
57
  };
58
58
 
59
59
  const queryRes = await this.executeUnsafeQuery(baseInfo, sql, [method]);
60
- const rows2: any[] = pickAndConvertRowsByMix(queryRes, sysDatabaseDbType);
60
+ const rows2: any[] = queryRes.rows || [];
61
61
  if (rows2.length > 0) {
62
62
  return parseMethodInfo(rows2[0]);
63
63
  }
@@ -73,7 +73,7 @@ class CrudProCachedCfgService extends CrudProServiceBase {
73
73
  sqlDbType: sysDatabaseDbType,
74
74
  };
75
75
  const queryRes = await this.executeUnsafeQuery(baseInfo, sql);
76
- const rows2: any[] = pickAndConvertRowsByMix(queryRes, sysDatabaseDbType);
76
+ const rows2: any[] = queryRes.rows || [];
77
77
  return rows2.map(row => {
78
78
  return parseMethodInfo(row);
79
79
  });