badmfck-api-server 2.3.6 → 2.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,7 +83,7 @@ async function Initializer(services) {
83
83
  exports.Initializer = Initializer;
84
84
  class APIService extends BaseService_1.BaseService {
85
85
  static nextLogID = 0;
86
- version = "2.3.6";
86
+ version = "2.3.7";
87
87
  options;
88
88
  monitor;
89
89
  monitorIndexFile;
@@ -95,7 +95,8 @@ export declare class MysqlService extends BaseService {
95
95
  constructor(options: MysqlServiceOptions);
96
96
  static executeQuery(query: MySqlQuery | MySqlQuery[]): Promise<MysqlResult[]>;
97
97
  init(): Promise<void>;
98
- rollbackTransaction(trx: ITransaction, donNotRemove?: boolean): Promise<void>;
98
+ commit(trx: ITransaction): Promise<MysqlError | null>;
99
+ rollbackTransaction(trx: ITransaction, donNotRemove?: boolean): Promise<MysqlError | null>;
99
100
  finishApp(): Promise<void>;
100
101
  storeTransactionAsProblem(trx: ITransaction, message: string): Promise<void>;
101
102
  recreatePool(): Promise<boolean>;
@@ -155,7 +155,7 @@ class MysqlService extends BaseService_1.BaseService {
155
155
  if (this.debug)
156
156
  console.log("Begin transaction with id ", tid);
157
157
  try {
158
- await conn.beginTransaction();
158
+ await conn.query("START TRANSACTION");
159
159
  const res = await conn.query("SET autocommit=0");
160
160
  if (this.debug)
161
161
  console.log("Transaction started, SET autocommit=0 ", tid, res);
@@ -218,7 +218,7 @@ class MysqlService extends BaseService_1.BaseService {
218
218
  message: "Transaction not found"
219
219
  };
220
220
  }
221
- this.rollbackTransaction(trx);
221
+ await this.rollbackTransaction(trx);
222
222
  return null;
223
223
  };
224
224
  exports.REQ_MYSQL_TCOMMIT.listener = async (tid) => {
@@ -238,18 +238,8 @@ class MysqlService extends BaseService_1.BaseService {
238
238
  this.transactions = this.transactions.filter(i => i.id !== tid);
239
239
  if (this.debug)
240
240
  console.log("Transaction pool:", this.transactions);
241
- try {
242
- await trx.conn.commit();
243
- trx.conn.removeAllListeners();
244
- trx.conn.release();
245
- if (this.debug)
246
- console.log("Commit completed:");
247
- }
248
- catch (e) {
249
- this.rollbackTransaction(trx);
250
- return this.createMysqlQueryError(e);
251
- }
252
- return null;
241
+ const err = await this.commit(trx);
242
+ return err;
253
243
  };
254
244
  exports.REQ_MYSQL_TRANSACTION.listener = async (data) => {
255
245
  if (!this.pool)
@@ -266,8 +256,7 @@ class MysqlService extends BaseService_1.BaseService {
266
256
  };
267
257
  let income = [];
268
258
  try {
269
- await conn.beginTransaction();
270
- await conn.query("SET autocommit=0");
259
+ await conn.query("START TRANSACTION; SET autocommit=0");
271
260
  }
272
261
  catch (e) {
273
262
  const err = this.createMysqlQueryError(e);
@@ -293,21 +282,27 @@ class MysqlService extends BaseService_1.BaseService {
293
282
  return { error: err, data: null };
294
283
  }
295
284
  }
296
- try {
297
- await conn.commit();
298
- }
299
- catch (e) {
300
- await this.rollbackTransaction(trx);
301
- const err = this.createMysqlQueryError(e);
302
- return { error: err, data: null };
303
- }
304
- return { error: null, data: income };
285
+ const err = await this.commit(trx);
286
+ return { error: err, data: income };
305
287
  };
306
288
  }
289
+ async commit(trx) {
290
+ try {
291
+ await trx.conn.query("COMMIT");
292
+ trx.conn.removeAllListeners();
293
+ trx.conn.release();
294
+ }
295
+ catch (e) {
296
+ await this.rollbackTransaction(trx);
297
+ return this.createMysqlQueryError(e);
298
+ }
299
+ return null;
300
+ }
307
301
  async rollbackTransaction(trx, donNotRemove) {
302
+ let err = null;
308
303
  try {
309
304
  console.log("Rollback started", trx.conn);
310
- await trx.conn.rollback();
305
+ await trx.conn.query("ROLLBACK");
311
306
  trx.conn.removeAllListeners();
312
307
  trx.conn.release();
313
308
  if (!donNotRemove)
@@ -317,8 +312,10 @@ class MysqlService extends BaseService_1.BaseService {
317
312
  }
318
313
  catch (e) {
319
314
  (0, LogService_1.logCrit)("${MysqlService.js}", "Can't rollback transaction", trx);
315
+ err = this.createMysqlQueryError(e);
320
316
  }
321
317
  this.storeTransactionAsProblem(trx, "rollback");
318
+ return err;
322
319
  }
323
320
  async finishApp() {
324
321
  console.log("Finishing mysql service");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.3.6",
3
+ "version": "2.3.7",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",