add rc_db functionality

This commit is contained in:
Shannon Sterz 2016-02-03 21:50:19 +01:00
parent 9428b83358
commit 092092e9d1

View file

@ -11,7 +11,31 @@ var connection = mysql.createConnection({
connection.connect(); connection.connect();
var RC = function () { var RC = function () {
connection.query('CREATE TABLE IF NOT EXISTS rc_switches', function(err, rows, fields) { connection.query('CREATE TABLE IF NOT EXISTS rc_switches (
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) {
if (err) throw err; if (err) throw err;
}); });
}; };
RC.prototype.findByID = function(id, callback) {
connection.query('SELECT * FROM rc_switches WHERE switch_id = ?', [id], callback);
};
RC.prototype.findAll = function(callback) {
connection.query('SELECT * FROM rc_switches', callback);
};
RC.prototype.delete = function(id, callback) {
connection.query('DELETE FROM posts WHERE id = ?',[id], callback);
};
RC.prototype.add = function(rc, callback) {
// var rc = {decimal: bool, value: FF00..., name:'Switch name'};
var query = connection.query('INSERT INTO rc_switches SET ?', rc, callback);
};