mythnode
Version:
130 lines (104 loc) • 2.48 kB
JavaScript
var mysql = require('mysql');
var EventEmitter = require("events").EventEmitter;
var mythNode = function() {
/* set up the event system */
EventEmitter.call(this);
this._options = {}
}
mythNode.prototype.connect = function() {
this.db = mysql.createConnection({
host: 'snowmyth',
user: 'mythtv',
password: 'l1sWV0UB',
database: 'mythconverg'
});
mythnode.emit('connect',this.db);
}
mythNode.prototype.load = function() {
this.channels();
this.jobqueue();
this.recordings();
this.schedules();
},
}
mythNode.prototype.channels = function() {
this.db.query('SELECT * from channel order by channum', function(err, rows) {
mythnode.channels = rows;
mythnode.emit('channels',rows);
});
},
}
mythNode.prototype.jobqueue = function() {
this.db.query('SELECT * from jobqueue order by schedruntime LIMIT 0 20', function(err, rows) {
mythnode.jobqueue = rows;
mythnode.emit('jobqueue',rows);
});
},
}
mythNode.prototype.recordings = function() {
this.db.query("SELECT * from recorded where autoexpire != '9999' order by starttime desc LIMIT 0 20", function(err, rows) {
mythnode.recordings = rows;
mythnode.emit('recordings',rows);
});
},
}
mythNode.prototype.schedules = function() {
this.db.query("SELECT * from record ", function(err, rows) {
mythnode.schedules = rows;
mythnode.emit('schedules',rows);
});
},
}
mythNode.prototype.set = function(key,value) {
if (arguments.length === 1) {
return this._options[key];
}
this._options[key] = value;
return this._options[key];
}
mythNode.prototype.get = mythNode.prototype.set;
/**
* Sets multiple SimpleDocs options.
*
* ####Example:
*
* keystone.set({test: value}) // sets the 'test' option to `value`
*
* @param {Object} options
* @api public
*/
mythNode.prototype.options = function(options) {
if (!arguments.length)
return this._options;
if (typeof options === 'object') {
var keys = Object.keys(options),
i = keys.length,
k;
while (i--) {
k = keys[i];
this.set(k, options[k]);
}
}
return this._options;
};
/**
* mythNode
*
* create a new instance
*
* ####Example:
* var mythnode = require('mythnode');
* var sd2 = new mythnode.mythNode();
*
* @api public
*/
mythNode.prototype.mythNode = mythNode;
var mythnode = module.exports = exports = new mythNode();
/**
* 2014 snowkeeper
* github.com/snowkeeper
* npmjs.org/snowkeeper
*
* Peace :0)
*
* */