@bee.js/node 0.0.71 → 0.0.73

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 (2) hide show
  1. package/beehive.js +14 -17
  2. package/package.json +1 -1
package/beehive.js CHANGED
@@ -32,44 +32,41 @@ module.exports = function hive(req = {}, res = {}, model = null) {
32
32
  let models = global.models;
33
33
  let relWhere = {};
34
34
 
35
- const dbExec = async function (SQL, binds = [], params = {}) {
35
+ const dbExec = async function (SQL, binds = [], params = {}, retryCount = 0) {
36
36
  let result = [];
37
+ const MAX_RETRIES = 2;
37
38
 
38
39
  try {
39
- if (global.configs.debug)
40
- console.log(`
41
- ${SQL}
42
- `);
40
+ if (global.configs.debug) console.log(SQL);
43
41
 
44
42
  global.beeDBPool = global.beeDBPool || beeORM.createPool(global.configs);
45
43
  result = await global.beeDBPool.query(SQL, binds);
46
44
  } catch (_error) {
47
45
  log("####################### DB ERROR #######################");
48
46
  log(_error);
49
- log({ SQL, binds });
47
+ log(SQL);
48
+ log(binds.join(","));
50
49
 
51
- if (_error.includes("read ECONNRESET")) {
52
- beeORM.createPool(global.configs);
53
- log("### db retry...");
54
- await dbExec(SQL, binds, params);
50
+ const isConnReset = _error?.message?.includes("ECONNRESET");
55
51
 
56
- return;
52
+ if (isConnReset && retryCount < MAX_RETRIES) {
53
+ log("### DB retry after ECONNRESET...");
54
+ global.beeDBPool = beeORM.createPool(global.configs);
55
+ return await dbExec(SQL, binds, params, retryCount + 1);
57
56
  }
58
57
 
59
- _error = e;
60
- errorCode = 502;
58
+ throw _error; // error after MAX_RETRIES
61
59
  } finally {
62
60
  if (global.configs.debug) debug.push(SQL);
63
61
  if (global.configs.debug && binds) debug.push(binds);
64
62
 
65
63
  if (params.container) {
66
64
  data[params.container] = result[0];
67
-
68
65
  if (counters) counters[params.container] = (result[0] || []).length;
69
66
  }
70
-
71
- return result[0];
72
67
  }
68
+
69
+ return result[0];
73
70
  };
74
71
 
75
72
  return Object.assign({}, res, {
@@ -278,7 +275,7 @@ module.exports = function hive(req = {}, res = {}, model = null) {
278
275
  ),
279
276
  ].join(",");
280
277
 
281
- script[0]["where"].push(`${model.table}.${field} IN(${array})`);
278
+ script[0]["where"].push(`${model.table}.${field} IN(${array ?? "null"})`);
282
279
 
283
280
  return this;
284
281
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bee.js/node",
3
- "version": "0.0.71",
3
+ "version": "0.0.73",
4
4
  "description": "A JavaScript framework for making Node.js API´s",
5
5
  "main": "index.js",
6
6
  "scripts": {