From 092092e9d19e132789ae7722e6ddef09642900b9 Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Wed, 3 Feb 2016 21:50:19 +0100 Subject: [PATCH] add rc_db functionality --- nodejs/models/rc_db.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/nodejs/models/rc_db.js b/nodejs/models/rc_db.js index 32f5929..bc370a1 100644 --- a/nodejs/models/rc_db.js +++ b/nodejs/models/rc_db.js @@ -11,7 +11,31 @@ var connection = mysql.createConnection({ connection.connect(); 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; }); +}; + +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); }; \ No newline at end of file