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
*/
DataSource.prototype.disconnect = function disconnect(cb) {
if (typeof this.adapter.disconnect === 'function') {
this.connected = false;
this.adapter.disconnect(cb);
} else if (cb) {
cb();
var self = this;
if (this.connected && (typeof this.adapter.disconnect === 'function')) {
this.adapter.disconnect(function(err, result) {
self.connected = false;
cb && cb(err, result);
});
} else {
process.nextTick(function() {
cb && cb();
});
}
};