Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Last active August 29, 2015 13:56
Show Gist options
  • Save bendrucker/9127359 to your computer and use it in GitHub Desktop.
Save bendrucker/9127359 to your computer and use it in GitHub Desktop.
Demonstration for SQLite3 lock case
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)
]);
});
});
});
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