Dia antes primera install
This commit is contained in:
89
node_modules/node-red-node-mysql/68-mysql.html
generated
vendored
Normal file
89
node_modules/node-red-node-mysql/68-mysql.html
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
|
||||
<script type="text/html" data-template-name="MySQLdatabase">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
||||
<input type="text" id="node-config-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-host"><i class="fa fa-globe"></i> <span data-i18n="mysql.label.host"></span></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> <span data-i18n="mysql.label.port"></span></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> <span data-i18n="mysql.label.user"></span></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> <span data-i18n="mysql.label.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> <span data-i18n="mysql.label.database"></span></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> <span data-i18n="mysql.label.timezone"></span></label>
|
||||
<input type="text" id="node-config-input-tz" placeholder="±hh:mm">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-charset"><i class="fa fa-language"></i> <span data-i18n="mysql.label.charset"></span></label>
|
||||
<input type="text" id="node-config-input-charset">
|
||||
</div>
|
||||
<div class="form-tips"><span data-i18n="[html]mysql.tip"></span></div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('MySQLdatabase',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
host: {value:"127.0.0.1",required:true},
|
||||
port: {value:"3306",required:true},
|
||||
db: {value:"",required:true},
|
||||
tz: {value:""},
|
||||
charset: {value:"UTF8"}
|
||||
},
|
||||
credentials: {
|
||||
user: {type: "text"},
|
||||
password: {type: "password"}
|
||||
},
|
||||
label: function() {
|
||||
return this.name || this.db;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-template-name="mysql">
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-mydb"><i class="fa fa-database"></i> <span data-i18n="mysql.label.database"></label>
|
||||
<input type="text" id="node-input-mydb">
|
||||
</div>
|
||||
</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>
|
||||
199
node_modules/node-red-node-mysql/68-mysql.js
generated
vendored
Normal file
199
node_modules/node-red-node-mysql/68-mysql.js
generated
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var reconnect = RED.settings.mysqlReconnectTime || 20000;
|
||||
var mysqldb = require('mysql2');
|
||||
|
||||
function MySQLNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.host = n.host;
|
||||
this.port = n.port;
|
||||
this.tz = n.tz || "local";
|
||||
this.charset = (n.charset || "UTF8_GENERAL_CI").toUpperCase();
|
||||
|
||||
this.connected = false;
|
||||
this.connecting = false;
|
||||
|
||||
this.dbname = n.db;
|
||||
this.setMaxListeners(0);
|
||||
var node = this;
|
||||
|
||||
function checkVer() {
|
||||
node.pool.query("SELECT version();", [], function(err, rows, fields) {
|
||||
if (err) {
|
||||
node.error(err);
|
||||
node.status({fill:"red",shape:"ring",text:RED._("mysql.status.badping")});
|
||||
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: RED.settings.mysqlConnectionLimit || 50,
|
||||
connectTimeout: 30000,
|
||||
charset: node.charset,
|
||||
decimalNumbers: true
|
||||
});
|
||||
}
|
||||
|
||||
// connection test
|
||||
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.connected = true;
|
||||
node.emit("state","connected");
|
||||
if (!node.check) { node.check = setInterval(checkVer, 290000); }
|
||||
connection.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
node.connect = function() {
|
||||
if (!node.connected && !node.connecting) {
|
||||
doConnect();
|
||||
}
|
||||
}
|
||||
|
||||
node.on('close', function(done) {
|
||||
if (node.tick) { clearTimeout(node.tick); }
|
||||
if (node.check) { clearInterval(node.check); }
|
||||
// node.connection.release();
|
||||
node.emit("state"," ");
|
||||
if (node.connected) {
|
||||
node.connected = false;
|
||||
node.pool.end(function(err) { done(); });
|
||||
}
|
||||
else {
|
||||
delete node.pool;
|
||||
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);
|
||||
this.status({});
|
||||
|
||||
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 {
|
||||
node.status({fill:"red",shape:"ring",text:info});
|
||||
}
|
||||
});
|
||||
|
||||
node.on("input", function(msg, send, done) {
|
||||
send = send || function() { node.send.apply(node,arguments) };
|
||||
if (node.mydbConfig.connected) {
|
||||
if (typeof msg.topic === 'string') {
|
||||
//console.log("query:",msg.topic);
|
||||
node.mydbConfig.pool.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
if (conn) {
|
||||
conn.release()
|
||||
}
|
||||
status = { fill: "red", shape: "ring", text: RED._("mysql.status.error") + ": " + err.code };
|
||||
node.status(status);
|
||||
node.error(err, msg);
|
||||
if (done) { done(); }
|
||||
return
|
||||
}
|
||||
|
||||
var bind = [];
|
||||
if (Array.isArray(msg.payload)) {
|
||||
bind = msg.payload;
|
||||
}
|
||||
else if (typeof msg.payload === 'object' && msg.payload !== null) {
|
||||
bind = msg.payload;
|
||||
}
|
||||
conn.config.queryFormat = Array.isArray(msg.payload) ? null : customQueryFormat
|
||||
conn.query(msg.topic, bind, function (err, rows) {
|
||||
conn.release()
|
||||
if (err) {
|
||||
status = { fill: "red", shape: "ring", text: RED._("mysql.status.error") + ": " + err.code };
|
||||
node.status(status);
|
||||
node.error(err, msg);
|
||||
}
|
||||
else {
|
||||
msg.payload = rows;
|
||||
send(msg);
|
||||
status = { fill: "green", shape: "dot", text: RED._("mysql.status.ok") };
|
||||
node.status(status);
|
||||
}
|
||||
if (done) { done(); }
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
else {
|
||||
if (typeof msg.topic !== 'string') { node.error("msg.topic : "+RED._("mysql.errors.notstring")); done(); }
|
||||
}
|
||||
}
|
||||
else {
|
||||
node.error(RED._("mysql.errors.notconnected"),msg);
|
||||
status = {fill:"red",shape:"ring",text:RED._("mysql.status.notconnected")};
|
||||
if (done) { done(); }
|
||||
}
|
||||
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(RED._("mysql.errors.notconfigured"));
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType("mysql",MysqlDBNodeIn);
|
||||
}
|
||||
|
||||
function customQueryFormat(query, values) {
|
||||
if (!values) {
|
||||
return query;
|
||||
}
|
||||
return query.replace(/\:(\w+)/g, function(txt, key) {
|
||||
if (values.hasOwnProperty(key)) {
|
||||
return this.escape(values[key]);
|
||||
}
|
||||
return txt;
|
||||
}.bind(this));
|
||||
}
|
||||
14
node_modules/node-red-node-mysql/LICENSE
generated
vendored
Normal file
14
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.
|
||||
59
node_modules/node-red-node-mysql/README.md
generated
vendored
Normal file
59
node_modules/node-red-node-mysql/README.md
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
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
|
||||
-------
|
||||
|
||||
Either use the `Node-RED Menu - Manage Palette - Install`, or run the following command in your Node-RED user directory - typically `~/.node-red`
|
||||
|
||||
npm i node-red-node-mysql
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Allows basic access to a MySQL database.
|
||||
|
||||
This node uses the **query** operation against the configured database. This does allow both INSERTS and DELETES.
|
||||
|
||||
By its very nature it allows SQL injection... so *be careful out there...*
|
||||
|
||||
The `msg.topic` must hold the *query* 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 *null* is returned.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
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;
|
||||
```
|
||||
|
||||
Documentation
|
||||
-----
|
||||
|
||||
<a href="https://www.npmjs.com/package/mysql" target="_new">Documentation</a> of the used Node.js package
|
||||
19
node_modules/node-red-node-mysql/locales/en-US/68-mysql.html
generated
vendored
Normal file
19
node_modules/node-red-node-mysql/locales/en-US/68-mysql.html
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
<script type="text/html" data-help-name="MySQLdatabase">
|
||||
<p>Add the credentials for accessing your database here.</p>
|
||||
<p>Timezone can be set like GMT, EST5EDT, UTC, etc</p>
|
||||
<p>The Charset defaults to the "old" 3 byte Mysql UTF8. If you need support for emojis etc then use UTF8MB4.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/html" 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. <b>Note</b>:
|
||||
these are of type <i>RowDataPacket</i>, and not a completely standard object.</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 in <b>settings.js</b>
|
||||
<pre>mysqlReconnectTime: 30000,</pre></p>
|
||||
</script>
|
||||
25
node_modules/node-red-node-mysql/locales/en-US/68-mysql.json
generated
vendored
Normal file
25
node_modules/node-red-node-mysql/locales/en-US/68-mysql.json
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"mysql": {
|
||||
"label": {
|
||||
"host": "Host",
|
||||
"port": "Port",
|
||||
"user": "User",
|
||||
"password": "Password",
|
||||
"database": "Database",
|
||||
"timezone": "Timezone",
|
||||
"charset": "Charset"
|
||||
},
|
||||
"status": {
|
||||
"badping": "Bad Ping",
|
||||
"error": "Error",
|
||||
"ok": "OK",
|
||||
"notconnected": "not yet connected"
|
||||
},
|
||||
"errors": {
|
||||
"notstring": "the query is not defined as a string",
|
||||
"notconnected": "Database not connected",
|
||||
"notconfigured": "MySQL database not configured"
|
||||
},
|
||||
"tip": "Tip: The timezone should be specified as ±hh:mm or leave blank for 'local'."
|
||||
}
|
||||
}
|
||||
18
node_modules/node-red-node-mysql/locales/ja/68-mysql.html
generated
vendored
Normal file
18
node_modules/node-red-node-mysql/locales/ja/68-mysql.html
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
<script type="text/html" data-help-name="MySQLdatabase">
|
||||
<p>データベースにアクセスするための認証情報を追加します。</p>
|
||||
<p>タイムゾーンには、GMT, EST5EDT, UTC のような値を設定します。</p>
|
||||
<p>文字セットのデフォルトは「古い」3バイトのMysql UTF8です。絵文字などをサポートする必要がある場合は、UTF8MB4 を使用してください。</p>
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-help-name="mysql">
|
||||
<p>MySQLデータベースに対するアクセスを提供します。</p>
|
||||
<p>このノードでは、設定したデータベースに対して <b>クエリ</b> 操作を行います。INSERTSとDELETESの両方が可能です。
|
||||
その性質上、SQLインジェクションが可能になりますので、<i>ご注意ください</i>。</p>
|
||||
<p><code>msg.topic</code> にはデータベースに対する <i>クエリ</i> を指定する必要があります。また、結果は <code>msg.payload</code> に格納されて返ります。</p>
|
||||
<p><code>msg.payload</code> には topic にバインドする値の配列を含めることができます。</p>
|
||||
<p>通常、返されるペイロードは、結果行の配列となります。 <b>注</b>: これらは<i>RowDataPacket</i>型であり、完全な標準オブジェクトではありません。</p>
|
||||
<p>キーに該当するものが見つからない場合、<i>null</i> が返ります。</p>
|
||||
<p>再接続のタイムアウト(ミリ秒)は、 <b>settings.js</b> に以下の1行追加することで変更できます。
|
||||
<pre>mysqlReconnectTime: 30000,</pre></p>
|
||||
</script>
|
||||
24
node_modules/node-red-node-mysql/locales/ja/68-mysql.json
generated
vendored
Normal file
24
node_modules/node-red-node-mysql/locales/ja/68-mysql.json
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"mysql": {
|
||||
"label": {
|
||||
"host": "ホスト",
|
||||
"port": "ポート",
|
||||
"user": "ユーザー",
|
||||
"password": "パスワード",
|
||||
"database": "データベース",
|
||||
"timezone": "タイムゾーン",
|
||||
"charset": "文字セット"
|
||||
},
|
||||
"status": {
|
||||
"badping": "Bad Ping",
|
||||
"error": "エラー",
|
||||
"ok": "OK",
|
||||
"notconnected": "未接続"
|
||||
},
|
||||
"errors": {
|
||||
"notstring": "クエリが文字列として定義されていません",
|
||||
"notconnected": "データベースに接続できません",
|
||||
"notconfigured": "MySQLデータベース未設定"
|
||||
}
|
||||
}
|
||||
}
|
||||
32
node_modules/node-red-node-mysql/package.json
generated
vendored
Normal file
32
node_modules/node-red-node-mysql/package.json
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "node-red-node-mysql",
|
||||
"version": "2.0.0",
|
||||
"description": "A Node-RED node to read and write to a MySQL database",
|
||||
"dependencies": {
|
||||
"mysql2": "^3.6.5"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/node-red/node-red-nodes.git",
|
||||
"directory": "tree/master/storage/mysql"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"node-red",
|
||||
"mysql"
|
||||
],
|
||||
"node-red": {
|
||||
"version": ">=3.0.0",
|
||||
"nodes": {
|
||||
"mysql": "68-mysql.js"
|
||||
}
|
||||
},
|
||||
"author": {
|
||||
"name": "Dave Conway-Jones",
|
||||
"email": "dceejay@gmail.com",
|
||||
"url": "http://nodered.org"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user