Intial Commit
This commit is contained in:
93
nodered/rootfs/data/node_modules/node-red-node-mysql/68-mysql.html
generated
vendored
Normal file
93
nodered/rootfs/data/node_modules/node-red-node-mysql/68-mysql.html
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
|
||||
<script type="text/x-red" data-template-name="MySQLdatabase">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-host"><i class="fa fa-globe"></i> Host</label>
|
||||
<input type="text" id="node-config-input-host">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-port"><i class="fa fa-random"></i> Port</label>
|
||||
<input type="text" id="node-config-input-port">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-user"><i class="fa fa-user"></i> User</label>
|
||||
<input type="text" id="node-config-input-user">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label>
|
||||
<input type="password" id="node-config-input-password">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-db"><i class="fa fa-database"></i> Database</label>
|
||||
<input type="text" id="node-config-input-db">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-tz"><i class="fa fa-clock-o"></i> Timezone</label>
|
||||
<input type="text" id="node-config-input-tz">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('MySQLdatabase',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
host: {value:"127.0.0.1",required:true},
|
||||
port: {value:"3306",required:true},
|
||||
//user: {value:"",required:true},
|
||||
//pass: {value:"",required:true},
|
||||
db: {value:"",required:true},
|
||||
tz: {value:""}
|
||||
},
|
||||
credentials: {
|
||||
user: {type: "text"},
|
||||
password: {type: "password"}
|
||||
},
|
||||
label: function() {
|
||||
return this.db;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="mysql">
|
||||
<div class="form-row">
|
||||
<label for="node-input-mydb"><i class="fa fa-database"></i> Database</label>
|
||||
<input type="text" id="node-input-mydb">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mysql">
|
||||
<p>Allows basic access to a MySQL database.</p>
|
||||
<p>This node uses the <b>query</b> operation against the configured database. This does allow both INSERTS and DELETES.
|
||||
By its very nature it allows SQL injection... so <i>be careful out there...</i></p>
|
||||
<p><code>msg.topic</code> must hold the <i>query</i> for the database, and the result is returned in <code>msg.payload</code>.</p>
|
||||
<p><code>msg.payload</code> can contain an array of values to bind to the topic.</p>
|
||||
<p>Typically the returned payload will be an array of the result rows.</p>
|
||||
<p>If nothing is found for the key then <i>null</i> is returned,</p>
|
||||
<p>The reconnect timeout in milliseconds can be changed by adding a line to <b>settings.js</b>
|
||||
<pre>mysqlReconnectTime: 30000,</pre></p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mysql',{
|
||||
category: 'storage-input',
|
||||
color:"#e97b00",
|
||||
defaults: {
|
||||
mydb: {type:"MySQLdatabase",required:true},
|
||||
name: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "db.png",
|
||||
label: function() {
|
||||
var levelNode = RED.nodes.node(this.mydb);
|
||||
return this.name||(levelNode?levelNode.label():"mysql");
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
166
nodered/rootfs/data/node_modules/node-red-node-mysql/68-mysql.js
generated
vendored
Normal file
166
nodered/rootfs/data/node_modules/node-red-node-mysql/68-mysql.js
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var reconnect = RED.settings.mysqlReconnectTime || 20000;
|
||||
var mysqldb = require('mysql');
|
||||
|
||||
function MySQLNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.host = n.host;
|
||||
this.port = n.port;
|
||||
this.tz = n.tz || "local";
|
||||
|
||||
this.connected = false;
|
||||
this.connecting = false;
|
||||
|
||||
this.dbname = n.db;
|
||||
this.setMaxListeners(0);
|
||||
var node = this;
|
||||
|
||||
function checkVer() {
|
||||
node.connection.query("SELECT version();", [], function(err, rows) {
|
||||
if (err) {
|
||||
node.connection.release();
|
||||
node.error(err);
|
||||
node.status({fill:"red",shape:"ring",text:"Bad Ping"});
|
||||
doConnect();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function doConnect() {
|
||||
node.connecting = true;
|
||||
node.emit("state","connecting");
|
||||
if (!node.pool) {
|
||||
node.pool = mysqldb.createPool({
|
||||
host : node.host,
|
||||
port : node.port,
|
||||
user : node.credentials.user,
|
||||
password : node.credentials.password,
|
||||
database : node.dbname,
|
||||
timezone : node.tz,
|
||||
insecureAuth: true,
|
||||
multipleStatements: true,
|
||||
connectionLimit: 25
|
||||
});
|
||||
}
|
||||
|
||||
node.pool.getConnection(function(err, connection) {
|
||||
node.connecting = false;
|
||||
if (err) {
|
||||
node.emit("state",err.code);
|
||||
node.error(err);
|
||||
node.tick = setTimeout(doConnect, reconnect);
|
||||
}
|
||||
else {
|
||||
node.connection = connection;
|
||||
node.connected = true;
|
||||
node.emit("state","connected");
|
||||
node.connection.on('error', function(err) {
|
||||
node.connected = false;
|
||||
node.connection.release();
|
||||
node.emit("state",err.code);
|
||||
if (err.code === 'PROTOCOL_CONNECTION_LOST') {
|
||||
doConnect(); // silently reconnect...
|
||||
}
|
||||
else if (err.code === 'ECONNRESET') {
|
||||
doConnect(); // silently reconnect...
|
||||
}
|
||||
else {
|
||||
node.error(err);
|
||||
doConnect();
|
||||
}
|
||||
});
|
||||
if (!node.check) { node.check = setInterval(checkVer, 290000); }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.connect = function() {
|
||||
if (!this.connected && !this.connecting) {
|
||||
doConnect();
|
||||
}
|
||||
}
|
||||
|
||||
this.on('close', function (done) {
|
||||
if (this.tick) { clearTimeout(this.tick); }
|
||||
if (this.check) { clearInterval(this.check); }
|
||||
node.connected = false;
|
||||
node.emit("state"," ");
|
||||
node.pool.end(function (err) { done(); });
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("MySQLdatabase",MySQLNode, {
|
||||
credentials: {
|
||||
user: {type: "text"},
|
||||
password: {type: "password"}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function MysqlDBNodeIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.mydb = n.mydb;
|
||||
this.mydbConfig = RED.nodes.getNode(this.mydb);
|
||||
|
||||
if (this.mydbConfig) {
|
||||
this.mydbConfig.connect();
|
||||
var node = this;
|
||||
var busy = false;
|
||||
var status = {};
|
||||
node.mydbConfig.on("state", function(info) {
|
||||
if (info === "connecting") { node.status({fill:"grey",shape:"ring",text:info}); }
|
||||
else if (info === "connected") { node.status({fill:"green",shape:"dot",text:info}); }
|
||||
else {
|
||||
if (info === "ECONNREFUSED") { info = "connection refused"; }
|
||||
if (info === "PROTOCOL_CONNECTION_LOST") { info = "connection lost"; }
|
||||
node.status({fill:"red",shape:"ring",text:info});
|
||||
}
|
||||
});
|
||||
|
||||
node.on("input", function(msg) {
|
||||
if (node.mydbConfig.connected) {
|
||||
if (typeof msg.topic === 'string') {
|
||||
var bind = Array.isArray(msg.payload) ? msg.payload : [];
|
||||
node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) {
|
||||
if (err) {
|
||||
node.error(err,msg);
|
||||
status = {fill:"red",shape:"ring",text:"Error"};
|
||||
}
|
||||
else {
|
||||
if (rows.constructor.name === "OkPacket") {
|
||||
msg.payload = JSON.parse(JSON.stringify(rows));
|
||||
}
|
||||
else { msg.payload = rows; }
|
||||
node.send(msg);
|
||||
status = {fill:"green",shape:"dot",text:"OK"};
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (typeof msg.topic !== 'string') { node.error("msg.topic : the query is not defined as a string"); }
|
||||
}
|
||||
}
|
||||
else {
|
||||
node.error("Database not connected",msg);
|
||||
status = {fill:"red",shape:"ring",text:"not yet connected"};
|
||||
}
|
||||
if (!busy) {
|
||||
busy = true;
|
||||
node.status(status);
|
||||
node.tout = setTimeout(function() { busy = false; node.status(status); },500);
|
||||
}
|
||||
});
|
||||
|
||||
node.on('close', function () {
|
||||
if (node.tout) { clearTimeout(node.tout); }
|
||||
node.mydbConfig.removeAllListeners();
|
||||
node.status({});
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.error("MySQL database not configured");
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType("mysql",MysqlDBNodeIn);
|
||||
}
|
||||
14
nodered/rootfs/data/node_modules/node-red-node-mysql/LICENSE
generated
vendored
Normal file
14
nodered/rootfs/data/node_modules/node-red-node-mysql/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
Copyright 2016 JS Foundation and other contributors, https://js.foundation/
|
||||
Copyright 2013-2016 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
29
nodered/rootfs/data/node_modules/node-red-node-mysql/README.md
generated
vendored
Normal file
29
nodered/rootfs/data/node_modules/node-red-node-mysql/README.md
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
-------
|
||||
|
||||
Run the following command in your Node-RED user directory - typically `~/.node-red`
|
||||
|
||||
npm install node-red-node-mysql
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Allows basic access to a MySQL database.
|
||||
|
||||
This node uses the <b>query</b> operation against the configured database. This does allow both INSERTS and DELETES.
|
||||
|
||||
By it's very nature it allows SQL injection... so <i>be careful out there...</i>
|
||||
|
||||
The `msg.topic` must hold the <i>query</i> for the database, and the result is returned in `msg.payload`.
|
||||
|
||||
Typically the returned payload will be an array of the result rows.
|
||||
|
||||
If nothing is found for the key then <i>null</i> is returned.
|
||||
|
||||
The reconnect retry timeout in milliseconds can be changed by adding a line to <b>settings.js</b>
|
||||
<pre>mysqlReconnectTime: 30000,</pre></p>
|
||||
53
nodered/rootfs/data/node_modules/node-red-node-mysql/package.json
generated
vendored
Normal file
53
nodered/rootfs/data/node_modules/node-red-node-mysql/package.json
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"_from": "node-red-node-mysql@0.0.19",
|
||||
"_id": "node-red-node-mysql@0.0.19",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-zWcn2rdKVCvZ7BVMIohVJf9/y2P+M6QZCVfcyl5Kg0aGcYOQ03X/MPANFlNwu3VwZgHEVJNGu3acFb27Jckh1g==",
|
||||
"_location": "/node-red-node-mysql",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "node-red-node-mysql@0.0.19",
|
||||
"name": "node-red-node-mysql",
|
||||
"escapedName": "node-red-node-mysql",
|
||||
"rawSpec": "0.0.19",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.0.19"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/node-red-node-mysql/-/node-red-node-mysql-0.0.19.tgz",
|
||||
"_shasum": "bf35d0596160566e12c4ef42a6b84d19544a6dfc",
|
||||
"_spec": "node-red-node-mysql@0.0.19",
|
||||
"_where": "/data",
|
||||
"author": {
|
||||
"name": "Dave Conway-Jones",
|
||||
"email": "ceejay@vnet.ibm.com",
|
||||
"url": "http://nodered.org"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"mysql": "^2.17.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A Node-RED node to read and write to a MySQL database",
|
||||
"keywords": [
|
||||
"node-red",
|
||||
"mysql"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"name": "node-red-node-mysql",
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
"mysql": "68-mysql.js"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/node-red/node-red-nodes/tree/master/storage/mysql"
|
||||
},
|
||||
"version": "0.0.19"
|
||||
}
|
||||
Reference in New Issue
Block a user