@ejfdelgado/ejflab-common 1.5.4 → 1.6.1

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.5.4",
4
+ "version": "1.6.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
@@ -10,7 +10,6 @@
10
10
  "scripts": {
11
11
  "mylogin": "npm login",
12
12
  "mypublish": "npm publish --access=public",
13
- "diff": "unset GTK_PATH && git difftool",
14
13
  "clean": "rm -rf node_modules && npm cache clean --force && rm package-lock.json && npm install"
15
14
  },
16
15
  "engines": {
@@ -26,6 +26,7 @@ const { SimpleObj } = require("../SimpleObj");
26
26
  const { CommandPrint } = require('./steps/CommandPrint');
27
27
  const { CommandMongo } = require('./steps/CommandMongo');
28
28
  const { CommandMinio } = require('./steps/CommandMinio');
29
+ const { CommandPostgres } = require('./steps/CommandPostgres.js');
29
30
 
30
31
  class FlowChartExec {
31
32
  executionPromise = null;
@@ -68,6 +69,7 @@ class FlowChartExec {
68
69
  this.registry["mongo"] = CommandMongo;
69
70
  this.registry["print"] = CommandPrint;
70
71
  this.registry["minio"] = CommandMinio;
72
+ this.registry["postgres"] = CommandPostgres;
71
73
  }
72
74
 
73
75
  registerTimeline(id, timeline) {
@@ -0,0 +1,50 @@
1
+ const { SimpleObj } = require("../../SimpleObj");
2
+ const { CommandBasic } = require("./CommandBasic");
3
+
4
+ class CommandPostgres extends CommandBasic {
5
+ async computation() {
6
+ const action = this.args[0];
7
+ const dbIdPath = this.args[1];
8
+ const bodyPath = this.args[2];
9
+ //srv/wideSight/sql/writes/object.sql
10
+ const script = this.args[3];
11
+ const postgresSrv = this.context.getSuperContext().getPostgresClient();
12
+ if (action == "execute") {
13
+ //console.log("Starting execute...");
14
+ const dbIdData = SimpleObj.getValue(this.context.data, dbIdPath, null);
15
+ let bodyData = SimpleObj.getValue(this.context.data, bodyPath, null);
16
+ bodyData = JSON.parse(JSON.stringify(bodyData));
17
+ if (!(bodyData instanceof Array)) {
18
+ bodyData = [bodyData]
19
+ }
20
+ const now = new Date().getTime();
21
+
22
+ const pool = postgresSrv.getPool();
23
+ const client = await pool.connect();
24
+ await client.query("BEGIN");
25
+ const response = [];
26
+ try {
27
+ // Insert into media
28
+ for (let i = 0; i < bodyData.length; i++) {
29
+ const payload = JSON.parse(JSON.stringify(dbIdData));
30
+ payload.object = bodyData[i];
31
+ payload.now = now;
32
+ const result = await postgresSrv.executeFile(script, payload, client);
33
+ response.push(result);
34
+ }
35
+ await client.query("COMMIT");
36
+ } catch (e) {
37
+ await client.query("ROLLBACK");
38
+ throw e;
39
+ } finally {
40
+ client.release();
41
+ }
42
+ //console.log("Finishing execute...");
43
+ //console.log(JSON.stringify(response));
44
+ }
45
+ }
46
+ }
47
+
48
+ module.exports = {
49
+ CommandPostgres
50
+ };