diff --git a/lib/datasource.js b/lib/datasource.js index e7ae5e51..4b9b3d4c 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -1,7 +1,6 @@ /** * Module dependencies */ - var ModelBuilder = require('./model-builder.js').ModelBuilder; var jutil = require('./jutil'); var ModelBaseClass = require('./model.js'); @@ -62,9 +61,9 @@ function DataSource(name, settings) { var connector = this.connector(); // DataAccessObject - connector defined or supply the default - this.DataAccessObject = connector.DataAccessObject || this.constructor.DataAccessObject; + this.DataAccessObject = (connector && connector.DataAccessObject) ? connector.DataAccessObject : this.constructor.DataAccessObject; this.DataAccessObject.call(this, arguments); - + // operation metadata this._operations = {}; @@ -116,7 +115,20 @@ for (var m in ModelBuilder) { DataSource.prototype.setup = function(name, settings) { var schema = this; + var adapter; + // support single settings object + if(typeof name === 'object') { + settings = name; + name = undefined; + } + if(settings) { + adapter = settings.connector || settings.adapter; + } + if(settings.initialize) { + adapter = settings; + } + // just save everything we get this.name = name; this.settings = settings; @@ -125,11 +137,10 @@ DataSource.prototype.setup = function(name, settings) { this.connected = false; this.connecting = false; - if (name) { + if (name && !adapter) { // and initialize schema using adapter // this is only one initialization entry point of adapter // this module should define `adapter` member of `this` (schema) - var adapter; if (typeof name === 'object') { adapter = name; this.name = adapter.name; @@ -201,6 +212,15 @@ DataSource.prototype.setup = function(name, settings) { }; } +/** + * Get the connector. + */ + +DataSource.prototype.connector = function () { + // alias for adapter compatibility + return this.adapter; +}; + /** * Define class * @@ -260,6 +280,9 @@ DataSource.prototype.define = function defineClass(className, properties, settin }; +// alias createModel +DataSource.prototype.createModel = DataSource.prototype.define; + /** * Mixin DataAccessObject methods. */ @@ -773,7 +796,6 @@ DataSource.prototype.discoverSchemasSync = function (owner, tableOrView, options }); // Add current tableOrView to the visited tables - options = options || {}; options.visited = options.visited || {}; var schemaKey = columns[0].owner + '.' + tableOrView; if (!options.visited.hasOwnProperty(schemaKey)) {