fix up rc_db module

This commit is contained in:
Shannon Sterz 2016-02-17 11:49:58 +01:00
parent 092092e9d1
commit a6c4c5d5ce

View file

@ -11,31 +11,27 @@ var connection = mysql.createConnection({
connection.connect(); connection.connect();
var RC = function () { var RC = function () {
connection.query('CREATE TABLE IF NOT EXISTS rc_switches ( connection.query('CREATE TABLE IF NOT EXISTS rc_switches ( switch_id INT(12) NOT NULL AUTO_INCREMENT, tristate BOOL DEFAULT NULL, on_value VARCHAR(16) NOT NULL, off_value VARCHAR(16) NOT NULL, name VARCHAR(200) DEFAULT NULL, PRIMARY KEY (switch_id) )'
switch_id INT(12) NOT NULL AUTO_INCREMENT,
decimal BOOL DEFAULT NULL,
value VARCHAR(16) NOT NULL,
name VARCHAR(200) DEFAULT NULL,
PRIMARY KEY (switch_id)
)'
, function(err, rows, fields) { , function(err, rows, fields) {
if (err) throw err; if (err) throw err;
}); });
}; }
RC.prototype.findByID = function(id, callback) { RC.prototype.find = function(id, callback) {
connection.query('SELECT * FROM rc_switches WHERE switch_id = ?', [id], callback); connection.query('SELECT * FROM rc_switches WHERE switch_id = ?', [id], callback);
}; }
RC.prototype.findAll = function(callback) { RC.prototype.findAll = function(callback) {
connection.query('SELECT * FROM rc_switches', callback); connection.query('SELECT * FROM rc_switches', callback);
}; }
RC.prototype.delete = function(id, callback) { RC.prototype.delete = function(id, callback) {
connection.query('DELETE FROM posts WHERE id = ?',[id], callback); connection.query('DELETE FROM rc_switches WHERE switch_id = ?',[id], callback);
}; }
RC.prototype.add = function(rc, callback) { RC.prototype.add = function(rc, callback) {
// var rc = {decimal: bool, value: FF00..., name:'Switch name'}; // var rc = {tristate: bool, value: FF00..., name:'Switch name'};
var query = connection.query('INSERT INTO rc_switches SET ?', rc, callback); connection.query('INSERT INTO rc_switches SET ?', rc, callback);
}; }
module.exports = RC;