Ability to transparently close connection with database

This commit is contained in:
Anatoliy Chakkaev 2011-10-21 16:46:09 +04:00
parent 182f3ff12e
commit 8b6c608c6c
4 changed files with 15 additions and 0 deletions

View File

@ -153,6 +153,10 @@ MongooseAdapter.prototype.updateAttributes = function updateAttrs(model, id, dat
});
};
MongooseAdapter.prototype.disconnect = function () {
this.client.connection.close();
};
function merge(base, update) {
Object.keys(update).forEach(function (key) {
base[key] = update[key];

View File

@ -191,3 +191,7 @@ BridgeToRedis.prototype.updateAttributes = function updateAttrs(model, id, data,
}.bind(this));
};
BridgeToRedis.prototype.disconnect = function disconnect() {
this.client.quit();
};

View File

@ -153,6 +153,12 @@ Schema.prototype.defineForeignKey = function defineForeignKey(className, key) {
}
};
Schema.prototype.disconnect = function disconnect() {
if (typeof this.adapter.disconnect === 'function') {
this.adapter.disconnect();
}
};
function hiddenProperty(where, property, value) {
Object.defineProperty(where, property, {

View File

@ -341,6 +341,7 @@ function testOrm(schema) {
});
function allTestsDone() {
schema.disconnect();
console.log('Test done in %dms\n', Date.now() - start);
}