diff --git a/config.json.sample b/config.json.sample index 02037cd..d2d03a1 100644 --- a/config.json.sample +++ b/config.json.sample @@ -19,6 +19,7 @@ "language": "en", "debugMode": false, "debugLevel": 1, + "dbType": "redis", "redisPort": 6379, "timezone": "Europe/London", "repoRoot": "https://github.com/reality/depressionbot/", diff --git a/database.js b/database.js index f2b39cf..9f2489b 100644 --- a/database.js +++ b/database.js @@ -8,30 +8,26 @@ var databank = require('databank'), */ var DatabaseDriver = function(config) { this.config = config; - this.databanks = {}; + this.databank = null; }; /** * Connect to or create a new DataBank */ DatabaseDriver.prototype.createDB = function(name, driver, schema, callback) { - if(!_.has(this.databanks, name)) { var params = { 'schema': schema }; if(driver == 'redis' && _.has(this.config, 'redisPort')) params.port = this.config.redisPort; if(driver == 'disk') params.dir = 'db'; - this.databanks[name] = Databank.get(driver, params); - this.databanks[name].connect({}, function(err) { + this.databank = Databank.get(driver, params); + this.databank.connect({}, function(err) { if(err) { console.log('Didn\'t manage to connect to the data source - ' + err); } else { - callback(this.databanks[name]); + callback(this.databank); } }.bind(this)); - } else { - callback(this.databanks[name]); - } }; exports.DatabaseDriver = DatabaseDriver; diff --git a/run.js b/run.js index d900ed2..4a7c474 100644 --- a/run.js +++ b/run.js @@ -147,6 +147,7 @@ DBot.prototype.reloadModules = function() { this.stringMap = {}; this.usage = {}; this.reloadConfig(); + this.ddb.createDB(name, this.config.dbType, {}, function(db) {}); try { this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); @@ -214,9 +215,6 @@ DBot.prototype.reloadModules = function() { 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) {}); } } @@ -235,7 +233,7 @@ DBot.prototype.reloadModules = function() { } module.name = name; - module.db = this.ddb.databanks[name]; + module.db = this.ddb.databank; module.config = this.config.modules[name]; // Load the module data