add rc_db functionality
This commit is contained in:
parent
9428b83358
commit
092092e9d1
1 changed files with 25 additions and 1 deletions
|
@ -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);
|
||||
};
|
Reference in a new issue