Set up connector from the data source
This commit is contained in:
parent
1970c99424
commit
ac76666b7b
|
@ -62,8 +62,7 @@ function DataSource(name, settings) {
|
|||
|
||||
this.setup(name, settings);
|
||||
|
||||
this.connector = this.connector || this.adapter;
|
||||
this.adapter = this.connector; // Keep the adapter as an alias to connector
|
||||
this._setupConnector();
|
||||
|
||||
// connector
|
||||
var connector = this.connector;
|
||||
|
@ -119,6 +118,32 @@ for (var m in ModelBuilder) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the connector instance for backward compatibility with JugglingDB schema/adapter
|
||||
* @private
|
||||
*/
|
||||
DataSource.prototype._setupConnector = function () {
|
||||
this.connector = this.connector || this.adapter; // The legacy JugglingDB adapter will set up `adapter` property
|
||||
this.adapter = this.connector; // Keep the adapter as an alias to connector
|
||||
if (this.connector) {
|
||||
if (!this.connector.dataSource) {
|
||||
// Set up the dataSource if the connector doesn't do so
|
||||
this.connector.dataSource = this;
|
||||
}
|
||||
this.connector.log = function (query, start) {
|
||||
dataSource.log(query, start);
|
||||
};
|
||||
|
||||
this.connector.logger = function (query) {
|
||||
var t1 = Date.now();
|
||||
var log = this.log;
|
||||
return function (q) {
|
||||
log(q || query, t1);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
DataSource.prototype.setup = function(name, settings) {
|
||||
var dataSource = this;
|
||||
var connector;
|
||||
|
@ -175,26 +200,12 @@ DataSource.prototype.setup = function(name, settings) {
|
|||
if (connector) {
|
||||
var postInit = function postInit() {
|
||||
|
||||
this.connector = this.connector || this.adapter;
|
||||
this.adapter = this.connector; // Keep the adapter as an alias to connector
|
||||
|
||||
this._setupConnector();
|
||||
// we have an connector now?
|
||||
if (!this.connector) {
|
||||
throw new Error('Connector is not defined correctly: it should create `connector` member of dataSource');
|
||||
}
|
||||
|
||||
this.connector.log = function (query, start) {
|
||||
dataSource.log(query, start);
|
||||
};
|
||||
|
||||
this.connector.logger = function (query) {
|
||||
var t1 = Date.now();
|
||||
var log = this.log;
|
||||
return function (q) {
|
||||
log(q || query, t1);
|
||||
};
|
||||
};
|
||||
|
||||
this.connected = true;
|
||||
this.emit('connected');
|
||||
|
||||
|
|
Loading…
Reference in New Issue