From e27acc887e4be4f6cfc5a43a126d6f5e3c9ea3e8 Mon Sep 17 00:00:00 2001 From: Balthasar Hofer Date: Tue, 13 Dec 2022 14:06:03 +0100 Subject: [PATCH 1/3] Provide `flow`- and `global` context to mustache atm it is not possible to access data other than `msg` within mustache. With this change, the `flow` and `global` context is accessible aswell inside mustache templates. --- postgresql.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/postgresql.js b/postgresql.js index e45040f..ac552f6 100644 --- a/postgresql.js +++ b/postgresql.js @@ -167,7 +167,11 @@ module.exports = function (RED) { } } else { const partsId = Math.random(); - let query = msg.query ? msg.query : Mustache.render(node.query, { msg }); + + const flowContext = this.flow.keys().reduce((prev, k) => ({...prev, [k]: this.flow.get(k)}), {}); + const globalContext = this.global.keys().reduce((prev, k) => ({...prev, [k]: this.global.get(k)}), {}); + + let query = msg.query ? msg.query : Mustache.render(node.query, { flow: flowContext, global: globalContext, msg }); let client = null; From 8f11effe59cd65f88effc9d05bf16697e6d62755 Mon Sep 17 00:00:00 2001 From: Balthasar Hofer Date: Tue, 13 Dec 2022 14:25:11 +0100 Subject: [PATCH 2/3] fix eslint --- postgresql.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgresql.js b/postgresql.js index ac552f6..210db66 100644 --- a/postgresql.js +++ b/postgresql.js @@ -168,8 +168,8 @@ module.exports = function (RED) { } else { const partsId = Math.random(); - const flowContext = this.flow.keys().reduce((prev, k) => ({...prev, [k]: this.flow.get(k)}), {}); - const globalContext = this.global.keys().reduce((prev, k) => ({...prev, [k]: this.global.get(k)}), {}); + const flowContext = this.flow.keys().reduce((prev, k) => ({ ...prev, [k]: this.flow.get(k) }), { }); + const globalContext = this.global.keys().reduce((prev, k) => ({ ...prev, [k]: this.global.get(k) }), { }); let query = msg.query ? msg.query : Mustache.render(node.query, { flow: flowContext, global: globalContext, msg }); From 9e1c0778c6b841ffb85650727f6d8a11ad7196eb Mon Sep 17 00:00:00 2001 From: Balthasar Hofer Date: Tue, 13 Dec 2022 14:28:48 +0100 Subject: [PATCH 3/3] [eslint] remove trailing spaces --- postgresql.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresql.js b/postgresql.js index 210db66..092e7fd 100644 --- a/postgresql.js +++ b/postgresql.js @@ -170,7 +170,7 @@ module.exports = function (RED) { const flowContext = this.flow.keys().reduce((prev, k) => ({ ...prev, [k]: this.flow.get(k) }), { }); const globalContext = this.global.keys().reduce((prev, k) => ({ ...prev, [k]: this.global.get(k) }), { }); - + let query = msg.query ? msg.query : Mustache.render(node.query, { flow: flowContext, global: globalContext, msg }); let client = null;