Add support to use adapter constructor for initialization
This commit is contained in:
parent
7684fe2946
commit
12199ad779
|
@ -170,7 +170,7 @@ DataSource.prototype.setup = function(name, settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adapter) {
|
if (adapter) {
|
||||||
adapter.initialize(this, function () {
|
var postInit = function postInit() {
|
||||||
|
|
||||||
// we have an adaper now?
|
// we have an adaper now?
|
||||||
if (!this.adapter) {
|
if (!this.adapter) {
|
||||||
|
@ -192,7 +192,16 @@ DataSource.prototype.setup = function(name, settings) {
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
this.emit('connected');
|
this.emit('connected');
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this);
|
||||||
|
|
||||||
|
if ('function' === typeof adapter.initialize) {
|
||||||
|
// Call the async initialize method
|
||||||
|
adapter.initialize(this, postInit);
|
||||||
|
} else if('function' === typeof adapter) {
|
||||||
|
// Use the adapter constructor directly
|
||||||
|
this.adapter = new adapter(this.settings);
|
||||||
|
postInit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
schema.connect = function(cb) {
|
schema.connect = function(cb) {
|
||||||
|
@ -277,7 +286,7 @@ DataSource.prototype.define = function defineClass(className, properties, settin
|
||||||
// add data access objects
|
// add data access objects
|
||||||
this.mixin(NewClass);
|
this.mixin(NewClass);
|
||||||
|
|
||||||
if(this.adapter) {
|
if(this.adapter && this.adapter.define) {
|
||||||
// pass control to adapter
|
// pass control to adapter
|
||||||
this.adapter.define({
|
this.adapter.define({
|
||||||
model: NewClass,
|
model: NewClass,
|
||||||
|
@ -344,7 +353,7 @@ DataSource.prototype.attach = function (ModelCtor) {
|
||||||
|
|
||||||
this.mixin(ModelCtor);
|
this.mixin(ModelCtor);
|
||||||
|
|
||||||
if(this.adapter) {
|
if(this.adapter && this.adapter.define) {
|
||||||
// pass control to adapter
|
// pass control to adapter
|
||||||
this.adapter.define({
|
this.adapter.define({
|
||||||
model: ModelCtor,
|
model: ModelCtor,
|
||||||
|
@ -1160,7 +1169,7 @@ DataSource.prototype.copyModel = function copyModel(Master) {
|
||||||
settings: md.settings
|
settings: md.settings
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!schema.isTransaction) {
|
if ((!schema.isTransaction) && schema.adapter && schema.adapter.define) {
|
||||||
schema.adapter.define({
|
schema.adapter.define({
|
||||||
model: Slave,
|
model: Slave,
|
||||||
properties: md.properties,
|
properties: md.properties,
|
||||||
|
|
Loading…
Reference in New Issue