forked from GitHub/dbot
Provisional framework for database module using databank multiplexing. [#272]
This commit is contained in:
parent
22238f95d1
commit
b288487f23
28
database.js
Normal file
28
database.js
Normal file
@ -0,0 +1,28 @@
|
||||
var databank = require('databank'),
|
||||
Databank = databank.Databank,
|
||||
DatabankObject = databank.DatabankObject;
|
||||
//DatabankStore = require('connect-databank')(express);
|
||||
|
||||
/**
|
||||
* Multiplex databank objects
|
||||
*/
|
||||
var DatabaseDriver = function() {
|
||||
this.databanks = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Connect to or create a new DataBank
|
||||
*/
|
||||
DatabaseDriver.prototype.createDB = function(name, driver, callback, schema) {
|
||||
var params = { 'schema': schema };
|
||||
this.databanks[name] = Databank.get(driver, params);
|
||||
this.databanks[name].connect({}, function(err) {
|
||||
if(err) {
|
||||
console.log('Didn\'t manage to connect to the data source.');
|
||||
} else {
|
||||
callback(this.databanks[name]);
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
exports.DatabaseDriver = DatabaseDriver;
|
28
run.js
28
run.js
@ -1,6 +1,7 @@
|
||||
var fs = require('fs'),
|
||||
_ = require('underscore')._,
|
||||
jsbot = require('./jsbot/jsbot');
|
||||
jsbot = require('./jsbot/jsbot'),
|
||||
DatabaseDriver = require('./database').DatabaseDriver;
|
||||
require('./snippets');
|
||||
|
||||
var DBot = function() {
|
||||
@ -22,6 +23,9 @@ var DBot = function() {
|
||||
this.db.config = {};
|
||||
}
|
||||
|
||||
/*** Load the fancy DB ***/
|
||||
this.ddb = new DatabaseDriver();
|
||||
|
||||
/*** Load the Config ***/
|
||||
|
||||
if(!fs.existsSync('config.json')) {
|
||||
@ -198,14 +202,22 @@ DBot.prototype.reloadModules = function() {
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
// Generate missing DB keys
|
||||
this.config[name] = config;
|
||||
_.each(config.dbKeys, function(dbKey) {
|
||||
if(!_.has(this.db, dbKey)) {
|
||||
this.db[dbKey] = {};
|
||||
}
|
||||
}, this);
|
||||
|
||||
// Groovy funky database shit
|
||||
if(!_.has(config, 'dbType') || config.dbType == 'olde') {
|
||||
// Generate missing DB keys
|
||||
_.each(config.dbKeys, function(dbKey) {
|
||||
if(!_.has(this.db, dbKey)) {
|
||||
this.db[dbKey] = {};
|
||||
}
|
||||
}, this);
|
||||
} else {
|
||||
// Just use the name of the module for now, add dbKey iteration later
|
||||
this.ddb.createDB(name, config.dbType, function(db) {
|
||||
module.db = db;
|
||||
}.bind(this), {});
|
||||
}
|
||||
|
||||
// Load the module itself
|
||||
var rawModule = require(moduleDir + name);
|
||||
|
Loading…
Reference in New Issue
Block a user