node-red-node-mysql
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -21,42 +21,3 @@ /** | ||
var mysqldb = require('mysql'); | ||
var querystring = require('querystring'); | ||
RED.httpAdmin.get('/MySQLdatabase/:id',function(req,res) { | ||
var credentials = RED.nodes.getCredentials(req.params.id); | ||
if (credentials) { | ||
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!=="")})); | ||
} else { | ||
res.send(JSON.stringify({})); | ||
} | ||
}); | ||
RED.httpAdmin.delete('/MySQLdatabase/:id',function(req,res) { | ||
RED.nodes.deleteCredentials(req.params.id); | ||
res.send(200); | ||
}); | ||
RED.httpAdmin.post('/MySQLdatabase/:id',function(req,res) { | ||
var body = ""; | ||
req.on('data', function(chunk) { | ||
body+=chunk; | ||
}); | ||
req.on('end', function(){ | ||
var newCreds = querystring.parse(body); | ||
var credentials = RED.nodes.getCredentials(req.params.id)||{}; | ||
if (newCreds.user == null || newCreds.user === "") { | ||
delete credentials.user; | ||
} else { | ||
credentials.user = newCreds.user; | ||
} | ||
if (newCreds.password === "") { | ||
delete credentials.password; | ||
} else { | ||
credentials.password = newCreds.password||credentials.password; | ||
} | ||
RED.nodes.addCredentials(req.params.id,credentials); | ||
res.send(200); | ||
}); | ||
}); | ||
function MySQLNode(n) { | ||
@@ -71,17 +32,2 @@ RED.nodes.createNode(this,n); | ||
var credentials = {}; | ||
if (n.user) { | ||
credentials.user = n.user; | ||
credentials.password = n.pass; | ||
RED.nodes.addCredentials(n.id,credentials); | ||
this.user = n.user; | ||
this.password = n.pass; | ||
} else { | ||
credentials = RED.nodes.getCredentials(n.id); | ||
if (credentials) { | ||
this.user = credentials.user; | ||
this.password = credentials.password; | ||
} | ||
} | ||
this.dbname = n.db; | ||
@@ -95,4 +41,4 @@ var node = this; | ||
port : node.port, | ||
user : node.user, | ||
password : node.password, | ||
user : node.credentials.user, | ||
password : node.credentials.password, | ||
database : node.dbname, | ||
@@ -130,3 +76,3 @@ timezone : node.tz, | ||
this.on('close', function () { | ||
this.on('close', function (done) { | ||
if (this.tick) { clearTimeout(this.tick); } | ||
@@ -136,7 +82,15 @@ if (this.connection) { | ||
if (err) { node.error(err); } | ||
done(); | ||
}); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
} | ||
RED.nodes.registerType("MySQLdatabase",MySQLNode); | ||
RED.nodes.registerType("MySQLdatabase",MySQLNode, { | ||
credentials: { | ||
user: {type: "text"}, | ||
password: {type: "password"} | ||
} | ||
}); | ||
@@ -155,3 +109,4 @@ | ||
//console.log("query:",msg.topic); | ||
node.mydbConfig.connection.query(msg.topic, function(err, rows) { | ||
var bind = Array.isArray(msg.payload) ? msg.payload : []; | ||
node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) { | ||
if (err) { node.warn(err); } | ||
@@ -158,0 +113,0 @@ else { |
{ | ||
"name" : "node-red-node-mysql", | ||
"version" : "0.0.4", | ||
"version" : "0.0.5", | ||
"description" : "A Node-RED node to read and write to a MySQL database", | ||
"dependencies" : { | ||
"mysql" : "2.3.*" | ||
"mysql" : "2.5.*" | ||
}, | ||
@@ -8,0 +8,0 @@ "repository" : { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19882
111
+ Addedbignumber.js@2.0.0(transitive)
+ Addedmysql@2.5.5(transitive)
+ Addedrequire-all@1.0.0(transitive)
- Removedbignumber.js@1.4.0(transitive)
- Removedmysql@2.3.2(transitive)
- Removedrequire-all@0.0.8(transitive)
Updatedmysql@2.5.*