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

Commit 14266ec7 by Holger

* implemented a (somewhat hacky) solution to provide persistent transactions on …

…memory resident sqlite databases
1 parent aaf87a93
......@@ -23,16 +23,17 @@ 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;
if (self.connections[options.uuid]) return Promise.resolve(self.connections[options.uuid]);
if (self.connections[options.inMemory||options.uuid]) return Promise.resolve(self.connections[options.inMemory||options.uuid]);
return new Promise(function (resolve, reject) {
self.connections[options.uuid] = new self.lib.Database(self.sequelize.options.storage || ':memory:', function(err) {
self.connections[options.inMemory||options.uuid] = new self.lib.Database(self.sequelize.options.storage || ':memory:', function(err) {
if (err) {
if (err.code === 'SQLITE_CANTOPEN') return reject('Failed to find SQL server. Please double check your settings.');
return reject(err);
}
resolve(self.connections[options.uuid]);
resolve(self.connections[options.inMemory||options.uuid]);
});
}).tap(function (connection) {
if (self.sequelize.options.foreignKeys !== false) {
......
......@@ -591,7 +591,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) return;
if (options.transaction || connection.filename == ":memory:") return;
return self.connectionManager.releaseConnection(connection);
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!