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

Commit a3a53654 by Sascha Depold

transaction support for count

1 parent b73243c6
......@@ -671,9 +671,10 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function(emitter) {
var sql = self.QueryGenerator.selectQuery(tableName, options)
, qry = self.sequelize.query(sql, null, { plain: true, raw: true, type: 'SELECT' })
, queryOptions = Utils._.extend({ transaction: options.transaction }, { plain: true, raw: true, type: 'SELECT' })
, query = self.sequelize.query(sql, null, queryOptions)
qry
query
.success(function(data) {
var result = data ? data[attributeSelector] : null
......
......@@ -3313,6 +3313,26 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
describe('count', function() {
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.count().success(function(count1) {
User.count({ transaction: t }).success(function(count2) {
expect(count1).to.equal(0)
expect(count2).to.equal(1)
t.rollback().success(done)
})
})
})
})
})
})
})
it('counts all created objects', function(done) {
var self = this
this.User.bulkCreate([{username: 'user1'}, {username: 'user2'}]).success(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!