Last active
August 29, 2015 13:56
-
-
Save bendrucker/9127359 to your computer and use it in GitHub Desktop.
Demonstration for SQLite3 lock case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should be able to run normal queries inside transaction blocks', function() { | |
return knex('accounts') | |
.returning('id') | |
.insert({ | |
first_name: 'Transacting', | |
last_name: 'User', | |
email:'transaction-test3@example.com', | |
logins: 1, | |
about: 'Lorem ipsum Dolore labore incididunt enim.', | |
created_at: new Date(), | |
updated_at: new Date() | |
}) | |
.then(function(resp) { | |
var id = resp[0]; | |
return knex.transaction(function(t) { | |
var transactionless = knex('accounts').where('id', id).select('first_name') | |
.then(function(resp) { | |
expect(resp).to.have.length(1); | |
}); | |
var Promise = require('bluebird'); | |
return Promise.all([ | |
transactionless, | |
Promise.delay(100).then(t.commit) | |
]); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should be able to run normal queries inside transaction blocks', function() { | |
return knex('accounts') | |
.returning('id') | |
.insert({ | |
first_name: 'Transacting', | |
last_name: 'User', | |
email:'transaction-test3@example.com', | |
logins: 1, | |
about: 'Lorem ipsum Dolore labore incididunt enim.', | |
created_at: new Date(), | |
updated_at: new Date() | |
}) | |
.then(function(resp) { | |
var id = resp[0]; | |
return knex.transaction(function(t) { | |
return knex('accounts').where('id', id).select('first_name') | |
.then(function(resp) { | |
expect(resp).to.have.length(1); | |
}) | |
.finally(t.commit); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment