badmfck-api-server 1.1.8 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,8 @@ export declare class MysqlService extends BaseService {
36
36
  reconnecting: boolean;
37
37
  pool: Pool | null;
38
38
  options: MysqlServiceOptions;
39
- retries: number;
39
+ serviceStarted: boolean;
40
+ queries: never[];
40
41
  constructor(options: MysqlServiceOptions);
41
42
  static executeQuery(query: MySqlQuery | MySqlQuery[]): Promise<MysqlResult[]>;
42
43
  init(): Promise<void>;
@@ -15,7 +15,8 @@ class MysqlService extends BaseService_1.BaseService {
15
15
  reconnecting = false;
16
16
  pool = null;
17
17
  options;
18
- retries = 5;
18
+ serviceStarted = false;
19
+ queries = [];
19
20
  constructor(options) {
20
21
  super("mysql");
21
22
  this.options = options;
@@ -23,12 +24,18 @@ class MysqlService extends BaseService_1.BaseService {
23
24
  }
24
25
  static async executeQuery(query) { return await exports.REQ_MYSQL_QUERY.request(query); }
25
26
  async init() {
27
+ this.serviceStarted = false;
26
28
  const ok = await this.createPool();
27
29
  if (!ok) {
28
30
  if (this.options.onLog)
29
31
  this.options.onLog(2, "Mysql server not connected, retrying in 3 sec");
30
32
  setTimeout(() => { this.init(); }, 3000);
31
33
  }
34
+ else {
35
+ this.serviceStarted = true;
36
+ if (this.options.onLog)
37
+ this.options.onLog(1, "Mysql Service started!");
38
+ }
32
39
  exports.REQ_MYSQL_QUERY.listener = async (data) => {
33
40
  if (!Array.isArray(data))
34
41
  data = [data];
@@ -98,7 +105,10 @@ class MysqlService extends BaseService_1.BaseService {
98
105
  static prepareQueryFieldValue(value, system) {
99
106
  if (!system && typeof value === "string") {
100
107
  value = value ? value.replaceAll('"', '\\"') : null;
101
- value = '"' + value + '"';
108
+ if (value !== null)
109
+ value = '"' + value + '"';
110
+ else
111
+ value = "NULL";
102
112
  }
103
113
  return value;
104
114
  }
@@ -121,6 +131,10 @@ class MysqlService extends BaseService_1.BaseService {
121
131
  });
122
132
  return;
123
133
  }
134
+ this.pool.on("error", (evt) => {
135
+ if (this.options.onLog)
136
+ this.options.onLog(2, `${evt}`);
137
+ });
124
138
  this.pool.getConnection((err, conn) => {
125
139
  if (err) {
126
140
  if (this.options.onLog)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",