badmfck-api-server 2.3.8 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,6 @@ import * as mysql from "mysql2/promise";
|
|
5
5
|
import fs from "fs";
|
6
6
|
export declare const S_MYSQL_STARTED: Signal<void>;
|
7
7
|
export declare const REQ_MYSQL_QUERY: Req<MySqlQuery | MySqlQuery[], MysqlResult[]>;
|
8
|
-
export declare const REQ_MYSQL_TRANSACTION: Req<MySqlQuery[], MysqlResult>;
|
9
8
|
export declare const REQ_MYSQL_TBEGIN: Req<void, number | MysqlError>;
|
10
9
|
export declare const REQ_MYSQL_TQUERY: Req<{
|
11
10
|
query: MySqlQuery;
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.MysqlService = exports.executeQuery = exports.REQ_MYSQL_TROLLBACK = exports.REQ_MYSQL_TCOMMIT = exports.REQ_MYSQL_TQUERY = exports.REQ_MYSQL_TBEGIN = exports.
|
29
|
+
exports.MysqlService = exports.executeQuery = exports.REQ_MYSQL_TROLLBACK = exports.REQ_MYSQL_TCOMMIT = exports.REQ_MYSQL_TQUERY = exports.REQ_MYSQL_TBEGIN = exports.REQ_MYSQL_QUERY = exports.S_MYSQL_STARTED = void 0;
|
30
30
|
const BaseService_1 = require("./BaseService");
|
31
31
|
const badmfck_signal_1 = __importStar(require("badmfck-signal"));
|
32
32
|
const crypto_1 = require("crypto");
|
@@ -36,7 +36,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
36
36
|
const path_1 = __importDefault(require("path"));
|
37
37
|
exports.S_MYSQL_STARTED = new badmfck_signal_1.default();
|
38
38
|
exports.REQ_MYSQL_QUERY = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_QUERY");
|
39
|
-
exports.REQ_MYSQL_TRANSACTION = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_TRANSACTION");
|
40
39
|
exports.REQ_MYSQL_TBEGIN = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_TRANSACTION_BEGING");
|
41
40
|
exports.REQ_MYSQL_TQUERY = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_TRANSACTION_ADD_OPERATION");
|
42
41
|
exports.REQ_MYSQL_TCOMMIT = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_TCOMMIT");
|
@@ -201,7 +200,7 @@ class MysqlService extends BaseService_1.BaseService {
|
|
201
200
|
console.log("Query execution status:", err ? err.message : "completed");
|
202
201
|
trx.queries.push({ sql: query, status: err ? err.message : "completed" });
|
203
202
|
return {
|
204
|
-
data: sqlData,
|
203
|
+
data: sqlData ? sqlData[0] : null,
|
205
204
|
error: err,
|
206
205
|
};
|
207
206
|
};
|
@@ -240,50 +239,6 @@ class MysqlService extends BaseService_1.BaseService {
|
|
240
239
|
const err = await this.commit(trx);
|
241
240
|
return err;
|
242
241
|
};
|
243
|
-
exports.REQ_MYSQL_TRANSACTION.listener = async (data) => {
|
244
|
-
if (!this.pool)
|
245
|
-
return { error: { code: "NO_POOL", errno: 100000, fatal: true, sql: "", name: "NO_POOL", message: "Mysql pool not created" }, data: null };
|
246
|
-
const conn = await this.pool.getConnection();
|
247
|
-
(0, LogService_1.logCrit)("${MysqlService.js}", "REQ_MYSQL_TRANSACTION deprecated, use REQ_MYSQL_TBEGIN, REQ_MYSQL_TQUERY, REQ_MYSQL_TCOMMIT, REQ_MYSQL_TROLLBACK");
|
248
|
-
if (!conn)
|
249
|
-
return { error: { code: "NO_CONN", errno: 100001, fatal: true, sql: "", name: "NO_CONN", message: "Mysql pool cant get connection" }, data: null };
|
250
|
-
const trx = {
|
251
|
-
id: MysqlService.nextTransactionID++,
|
252
|
-
timestamp: Date.now(),
|
253
|
-
conn: conn,
|
254
|
-
queries: []
|
255
|
-
};
|
256
|
-
let income = [];
|
257
|
-
try {
|
258
|
-
await conn.query("START TRANSACTION");
|
259
|
-
}
|
260
|
-
catch (e) {
|
261
|
-
const err = this.createMysqlQueryError(e);
|
262
|
-
this.storeTransactionAsProblem(trx, err.message);
|
263
|
-
return { error: err, data: null };
|
264
|
-
}
|
265
|
-
for (let i of data) {
|
266
|
-
const query = MysqlService.prepareQuery(i.query, i.fields);
|
267
|
-
let err = null;
|
268
|
-
try {
|
269
|
-
const d = await conn.query(query);
|
270
|
-
income.push(d[0]);
|
271
|
-
}
|
272
|
-
catch (e) {
|
273
|
-
err = this.createMysqlQueryError(e);
|
274
|
-
}
|
275
|
-
trx.queries.push({
|
276
|
-
sql: query,
|
277
|
-
status: err ? err.message : "completed"
|
278
|
-
});
|
279
|
-
if (err) {
|
280
|
-
this.storeTransactionAsProblem(trx, err.message);
|
281
|
-
return { error: err, data: null };
|
282
|
-
}
|
283
|
-
}
|
284
|
-
const err = await this.commit(trx);
|
285
|
-
return { error: err, data: income };
|
286
|
-
};
|
287
242
|
}
|
288
243
|
async commit(trx) {
|
289
244
|
try {
|
@@ -457,8 +412,18 @@ class MysqlService extends BaseService_1.BaseService {
|
|
457
412
|
return obj;
|
458
413
|
const fields = [];
|
459
414
|
for (let i in obj) {
|
460
|
-
if (typeof obj[i] === "object") {
|
461
|
-
|
415
|
+
if (obj[i] && typeof obj[i] === "object") {
|
416
|
+
let mo = obj[i];
|
417
|
+
if (!mo) {
|
418
|
+
mo = {
|
419
|
+
name: i,
|
420
|
+
value: null,
|
421
|
+
system: false,
|
422
|
+
ignoreInInsert: false,
|
423
|
+
ignoreInUpdate: false,
|
424
|
+
useInReplace: false
|
425
|
+
};
|
426
|
+
}
|
462
427
|
fields.push({
|
463
428
|
name: i,
|
464
429
|
value: mo.value,
|
@@ -673,16 +638,17 @@ class MysqlService extends BaseService_1.BaseService {
|
|
673
638
|
});
|
674
639
|
}
|
675
640
|
async queryAsync(conn, query) {
|
641
|
+
let result = null;
|
676
642
|
try {
|
677
|
-
|
678
|
-
return {
|
679
|
-
err: null,
|
680
|
-
results: result[0],
|
681
|
-
};
|
643
|
+
result = await conn.query(query);
|
682
644
|
}
|
683
645
|
catch (e) {
|
684
646
|
return { err: this.createMysqlQueryError(e) };
|
685
647
|
}
|
648
|
+
return {
|
649
|
+
err: null,
|
650
|
+
results: result[0],
|
651
|
+
};
|
686
652
|
}
|
687
653
|
createMysqlQueryError(err) {
|
688
654
|
if (err && typeof err === "object" && "code" in err && "errno" in err && "sql" in err && "name" in err && "message" in err) {
|