alexandrainst / node-red-contrib-postgresql

Node-RED node for PostgreSQL, supporting parameters, split, back-pressure
https://flows.nodered.org/node/node-red-contrib-postgresql
Apache License 2.0
31 stars 13 forks source link

Provide `flow`- and `global` context to mustache #29

Open lebalz opened 1 year ago

lebalz commented 1 year ago

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.

lebalz commented 1 year ago

@Alkarex Thanks for the awesome pg-node!

I had no time to set it up local and to test it. Even i think it shall work, a carefull review seems to be needed. Thanks :)

Alkarex commented 1 year ago

Thanks for the PR. I am a bit hesitating. I am afraid of a number of possible regressions due to that, in particular on performance (in case of many and/or large values), or unwanted side effects (I have not checked in details whether we risk calling some functions as properties or sub-properties of some context values). To access those context values, I would rather expose them in the msg object upstream. It is not possible to call functions from Mustache, is it?

lebalz commented 1 year ago

I see your concerns. I think mustache can somehow call function with a special annotation and setup of the function, but their examples are not working at all in the context of NR.

Probably another approach would be to add the possibility to add custom fields/expressions within the pg node? Those are then evaluated and passed to mustache?

This feature would be nice for portability. In my case, i have the exact same flow except the db-table name. It would be nice, if i only need to set a flow variable once and then use it in the queries...