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

Commit 608e5744 by Sascha Depold

transaction support for exec

1 parent 69b8fc30
Showing with 27 additions and 2 deletions
...@@ -93,8 +93,13 @@ module.exports = (function() { ...@@ -93,8 +93,13 @@ module.exports = (function() {
return SqlString.format(query.text.replace(/(\$\d)/g, '?'), query.values, null, dialect) + ';' return SqlString.format(query.text.replace(/(\$\d)/g, '?'), query.values, null, dialect) + ';'
} }
result.exec = function() { result.exec = function(options) {
return self.QueryInterface.queryAndEmit([result.toSql(), self, { type: 'SELECT' }], 'snafu') options = Utils._.extend({
transaction: null,
type: 'SELECT'
}, options || {})
return self.QueryInterface.queryAndEmit([result.toSql(), self, options], 'snafu')
} }
return result return result
......
...@@ -4249,6 +4249,26 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -4249,6 +4249,26 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
.then(function() { done() }) .then(function() { done() })
}) })
it('supports transactions', function(done) {
Support.prepareTransactionTest(dialect, this.sequelize, function(sequelize) {
var User = sequelize.define('User', { username: Sequelize.STRING })
User.sync({ force: true }).success(function() {
sequelize.transaction(function(t) {
User.create({ username: 'foo' }, { transaction: t }).success(function() {
User.where({ username: "foo" }).exec().success(function(users1) {
User.where({ username: "foo" }).exec({ transaction: t }).success(function(users2) {
expect(users1).to.have.length(0)
expect(users2).to.have.length(1)
done()
})
})
})
})
})
})
})
it("selects all users with name 'foo'", function(done) { it("selects all users with name 'foo'", function(done) {
this this
.User .User
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!