Improve connect/disconnect

This commit is contained in:
Raymond Feng 2013-05-31 13:10:09 -07:00
parent 1bb8047b57
commit 9d74759f90
1 changed files with 10 additions and 5 deletions

View File

@ -752,11 +752,16 @@ DataSource.prototype.defineForeignKey = function defineForeignKey(className, key
* Close database connection * Close database connection
*/ */
DataSource.prototype.disconnect = function disconnect(cb) { DataSource.prototype.disconnect = function disconnect(cb) {
if (typeof this.adapter.disconnect === 'function') { var self = this;
this.connected = false; if (this.connected && (typeof this.adapter.disconnect === 'function')) {
this.adapter.disconnect(cb); this.adapter.disconnect(function(err, result) {
} else if (cb) { self.connected = false;
cb(); cb && cb(err, result);
});
} else {
process.nextTick(function() {
cb && cb();
});
} }
}; };