node-red-contrib-postgresql icon indicating copy to clipboard operation
node-red-contrib-postgresql copied to clipboard

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

Open lebalz opened this issue 3 years ago • 3 comments

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 avatar Dec 13 '22 13:12 lebalz

@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 :)

lebalz avatar Dec 13 '22 13:12 lebalz

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?

Alkarex avatar Dec 13 '22 21:12 Alkarex

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...

lebalz avatar Dec 14 '22 09:12 lebalz