How to action MySQL queries inside function node?

Good day,

I'm trying to transition one of my flows away from using global context, to MySQL so the data is available to other sources outside Node-RED.

It's a real headache.

The function in question is rather complex (circa 800 lines) and processes an incoming payload, saving / retrieving various values to context as it runs... The question is, how can I transfer this to MySQL?

In essence I need a way to save / retrieve values from the database inside my function node (to access stored data, or update stored data). I've tried using node.send to dynamically generate the topic payload for the MySQL node (sent via a dedicated output), but it's way too quirky and complex generating the query strings.

Can anyone point me in the right direction, I'm likely not seeing an obvious solution...?


https://flows.nodered.org/flow/13c55d1aa11e864609e24fa534a1fa26

I've seen this, sadly it's a very simple example. I need to read / write over 50 variables during the function process - I can't exit the function to make queries...

Is node-red the right tool for the job in your case ? A function node with 800 lines with 50 variables defeats the purpose a little (but it could also be inefficient code), but yes dynamic queries would be the way to go, then again, this could also be inefficient (making individual calls to a db is expensive and relatively slow in performance).