connection.js
* @module greppy/db/connection
* @author Hermann Mayer <hermann.mayer92@gmail.com>
* @param {String} name - Name of the connection
* @param {String} backend - Name of the backend
* @param {Object} config - Backend configuration
var Connection = function(name, backend, config)
this.backend = new (require('./adapter/' + backend))(name, config);
throw new Error('Backend adapter "' + backend + '" does not exist.');
* @param {Function} callback - Function to call on finish
Connection.prototype.configure = function(callback)
this.backend.configure(function(err, instance, orm) {
if ('string' !== typeof err) {
err = '\n' + JSON.stringify(err, null, ' ');
'Failed to configure ' + self.backendName.yellow + '.' +
self.name.red + '. Details:' + err
return callback && callback(err);
'Connection' + ' (' + (self.backendName + '.' +
self.name).green.bold + ')' + ' is established'
* @param {Function} callback - Function to call on finish
Connection.prototype.close = function(callback)
* Get the ORM specific objects (ORM and models array).
* @param {Function} callback - Function to call on finish
Connection.prototype.getORM = function(callback)
throw new Error('ORM was not configured for the "' + this.name + '" connection');
callback && callback(this.orm.instance, this.orm.models, this.orm.utils || null);