update mysql node to use RED.httpAdmin

This commit is contained in:
Dave C-J 2014-02-23 18:32:49 +00:00
parent 3a6ffdf52b
commit 3d78a93958
1 changed files with 8 additions and 8 deletions

View File

@ -19,7 +19,7 @@ var reconnect = RED.settings.mysqlReconnectTime || 30000;
var mysqldb = require('mysql'); var mysqldb = require('mysql');
var querystring = require('querystring'); var querystring = require('querystring');
RED.app.get('/MySQLdatabase/:id',function(req,res) { RED.httpAdmin.get('/MySQLdatabase/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")})); res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
@ -28,12 +28,12 @@ RED.app.get('/MySQLdatabase/:id',function(req,res) {
} }
}); });
RED.app.delete('/MySQLdatabase/:id',function(req,res) { RED.httpAdmin.delete('/MySQLdatabase/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id); RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
RED.app.post('/MySQLdatabase/:id',function(req,res) { RED.httpAdmin.post('/MySQLdatabase/:id',function(req,res) {
var body = ""; var body = "";
req.on('data', function(chunk) { req.on('data', function(chunk) {
body+=chunk; body+=chunk;
@ -61,10 +61,10 @@ function MySQLNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.host = n.host; this.host = n.host;
this.port = n.port; this.port = n.port;
this.connected = false; this.connected = false;
this.connecting = false; this.connecting = false;
if (n.user) { if (n.user) {
var credentials = {}; var credentials = {};
credentials.user = n.user; credentials.user = n.user;
@ -79,7 +79,7 @@ function MySQLNode(n) {
this.password = credentials.password; this.password = credentials.password;
} }
} }
this.dbname = n.db; this.dbname = n.db;
var node = this; var node = this;
@ -114,13 +114,13 @@ function MySQLNode(n) {
} }
}); });
} }
this.connect = function() { this.connect = function() {
if (!this.connected && !this.connecting) { if (!this.connected && !this.connecting) {
doConnect(); doConnect();
} }
} }
this.on('close', function () { this.on('close', function () {
if (this.tick) { clearTimeout(this.tick); } if (this.tick) { clearTimeout(this.tick); }
if (this.connection) { if (this.connection) {