Closed kolaval closed 1 year ago
Hello, This is an interesting approach, which I have not investigated. It would require some minor refactoring to allow that elegantly. PR welcome!
At a quick glance, the node-red-node-mysql
node referred by the article does not seem to allow such a usage
https://github.com/node-red/node-red-nodes/blob/master/storage/mysql/68-mysql.js
which makes me doubt whether that article ever worked.
Alternatively, you can use the underlying pg
library from a node function: https://github.com/brianc/node-postgres
Is it possible to query postgres directly in a node-red function? I found an article that explains the process for mysql and I'm hoping that there's something similar. `// Initialize the MySQL node var mysql = context.get('mysql');
// Define the SQL query to be executed var sql = 'SELECT * FROM users WHERE id = 1';
// Execute the query and retrieve the results var result = await mysql.query(sql);
// Use the results in your JavaScript code msg.payload = result;`
https://community.home-assistant.io/t/access-sql-database-from-within-a-node-red-function-node/501344