2014-07-04 18:26:20 +02:00
|
|
|
node-red-node-mysql
|
|
|
|
========================
|
|
|
|
A <a href="http://nodered.org" target="_new">Node-RED</a> node to read and write to a MySQL database.
|
|
|
|
|
|
|
|
Install
|
|
|
|
-------
|
|
|
|
|
2020-03-01 18:06:22 +01:00
|
|
|
Either use the `Node-RED Menu - Manage Palette - Install`, or run the following command in your Node-RED user directory - typically `~/.node-red`
|
2014-07-04 18:26:20 +02:00
|
|
|
|
2020-03-20 15:59:08 +01:00
|
|
|
npm i node-red-node-mysql
|
2014-07-04 18:26:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
|
|
|
Allows basic access to a MySQL database.
|
|
|
|
|
2020-04-18 19:03:59 +02:00
|
|
|
This node uses the **query** operation against the configured database. This does allow both INSERTS and DELETES.
|
2014-07-04 18:26:20 +02:00
|
|
|
|
2020-04-18 19:03:59 +02:00
|
|
|
By its very nature it allows SQL injection... so *be careful out there...*
|
2014-07-04 18:26:20 +02:00
|
|
|
|
2020-04-18 19:03:59 +02:00
|
|
|
The `msg.topic` must hold the *query* for the database, and the result is returned in `msg.payload`.
|
2014-07-04 18:26:20 +02:00
|
|
|
|
|
|
|
Typically the returned payload will be an array of the result rows.
|
|
|
|
|
2020-04-18 19:03:59 +02:00
|
|
|
If nothing is found for the key then *null* is returned.
|
2014-07-04 18:26:20 +02:00
|
|
|
|
2020-04-18 19:03:59 +02:00
|
|
|
The reconnect retry timeout in milliseconds can be changed by adding a line to **settings.js**
|
|
|
|
```javascript
|
|
|
|
mysqlReconnectTime: 30000,
|
|
|
|
```
|
|
|
|
|
|
|
|
The timezone can be set like GMT, EST5EDT, UTC, etc.
|
|
|
|
|
|
|
|
The charset defaults to the "old" Mysql 3 byte UTF. If you need support for emojis etc then use UTF8MB4.
|
2020-04-10 23:53:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
Preparing Queries
|
|
|
|
-----
|
|
|
|
```javascript
|
|
|
|
msg.payload=[24, 'example-user'];
|
|
|
|
msg.topic="INSERT INTO users (`userid`, `username`) VALUES (?, ?);"
|
|
|
|
return msg;
|
|
|
|
```
|
|
|
|
|
|
|
|
with named parameters:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
msg.payload={}
|
|
|
|
msg.payload.userToChange=42;
|
|
|
|
msg.payload.newUsername="example-user";
|
|
|
|
msg.topic="INSERT INTO users (`userid`, `username`) VALUES (:userToChange, :newUsername) ON DUPLICATE KEY UPDATE `username`=:newUsername;"
|
|
|
|
return msg;
|
|
|
|
```
|
2020-04-18 19:03:59 +02:00
|
|
|
|
2020-04-10 23:53:17 +02:00
|
|
|
Documentation
|
|
|
|
-----
|
2020-04-18 19:03:59 +02:00
|
|
|
|
2020-04-10 23:53:17 +02:00
|
|
|
<a href="https://www.npmjs.com/package/mysql" target="_new">Documentation</a> of the used Node.js package
|