2013-02-12 20:15:32 +01:00
|
|
|
var databank = require('databank'),
|
|
|
|
Databank = databank.Databank,
|
2013-07-08 12:06:34 +02:00
|
|
|
DatabankObject = databank.DatabankObject,
|
|
|
|
_ = require('underscore')._;
|
2013-02-12 20:15:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplex databank objects
|
|
|
|
*/
|
2013-07-08 12:06:34 +02:00
|
|
|
var DatabaseDriver = function(config) {
|
|
|
|
this.config = config;
|
2015-02-09 17:54:59 +01:00
|
|
|
this.databank = null;
|
2013-02-12 20:15:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect to or create a new DataBank
|
|
|
|
*/
|
2013-04-10 02:19:56 +02:00
|
|
|
DatabaseDriver.prototype.createDB = function(name, driver, schema, callback) {
|
2015-02-09 17:56:29 +01:00
|
|
|
var params = { 'schema': schema };
|
2013-02-16 18:37:23 +01:00
|
|
|
|
2015-02-09 17:56:29 +01:00
|
|
|
if(driver == 'redis' && _.has(this.config, 'redisPort')) params.port = this.config.redisPort;
|
|
|
|
if(driver == 'disk') params.dir = 'db';
|
2013-02-16 18:37:23 +01:00
|
|
|
|
2015-02-09 17:56:29 +01:00
|
|
|
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.databank);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-02-12 20:15:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.DatabaseDriver = DatabaseDriver;
|