This repository has been archived on 2024-01-30. You can view files and clone it, but cannot push or open issues or pull requests.
trev/nodejs/models/rc_db.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-02-01 16:07:55 +01:00
var mysql = require('mysql');
var config = require('../config');
var connection = mysql.createConnection({
host : config.mysql_host,
user : config.mysql_user,
password : config.mysql_secret,
database : config.mysql_database
});
connection.connect();
var RC = function () {
2016-02-03 21:50:19 +01:00
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) {
2016-02-01 16:07:55 +01:00
if (err) throw err;
});
2016-02-03 21:50:19 +01:00
};
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);
2016-02-01 16:07:55 +01:00
};