不要怂,就是干,撸起袖子干!

Commit 1497e0dc by Mick Hansen

implement changes needed for #2380

1 parent c96e376f
......@@ -11,6 +11,9 @@ ConnectionManager = function(dialect, sequelize) {
this.dialect = dialect;
this.connections = {};
// We attempt to parse file location from a connection uri but we shouldn't match sequelize default host.
if (this.sequelize.options.host === 'localhost') delete this.sequelize.options.host;
try {
this.lib = require(sequelize.config.dialectModulePath || 'sqlite3').verbose();
} catch (err) {
......@@ -24,7 +27,7 @@ ConnectionManager.prototype.getConnection = function(options) {
var self = this;
options = options || {};
options.uuid = options.uuid || 'default';
options.inMemory = ((self.sequelize.options.storage || ':memory:') === ':memory:')?1:0;
options.inMemory = ((self.sequelize.options.storage || self.sequelize.options.host || ':memory:') === ':memory:') ? 1 : 0;
if (self.connections[options.inMemory || options.uuid]) return Promise.resolve(self.connections[options.inMemory || options.uuid]);
......@@ -45,9 +48,12 @@ ConnectionManager.prototype.getConnection = function(options) {
});
};
ConnectionManager.prototype.releaseConnection = function(connection) {
ConnectionManager.prototype.releaseConnection = function(connection, force) {
if (connection.filename === ":memory:" && force !== true) return;
if (connection.uuid) {
connection.close();
delete this.connections[connection.uuid];
}
};
......
......@@ -676,7 +676,7 @@ module.exports = (function() {
).then(function (connection) {
var query = new self.dialect.Query(connection, self, callee, options);
return query.run(sql).finally(function() {
if (options.transaction || (connection.filename === ":memory:")) return;
if (options.transaction) return;
return self.connectionManager.releaseConnection(connection);
});
});
......
......@@ -87,12 +87,13 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
});
if (dialect === 'sqlite'){
it('provides persistent transactions', function (done) {
it('provides persistent transactions', function () {
var sequelize = new Support.Sequelize('database', 'username', 'password', {dialect: 'sqlite'}),
User = sequelize.define('user', {
username: Support.Sequelize.STRING,
awesome: Support.Sequelize.BOOLEAN
});
return sequelize.transaction()
.then(function(t) {
return sequelize.sync({transaction:t})
......@@ -114,9 +115,6 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
})
.then(function(users) {
return expect(users.length).to.equal(1);
})
.then(function(object) {
done();
});
});
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!