Transactions not working as expected
See original GitHub issueHi - great work on Knex first of all! however having some trouble with transactions. I followed the example from the docs but it didn’t work so tried to simplify it more and can’t even get the following to work:
var Promise = require('bluebird');
knex.transaction(function(trx) {
return trx
.insert({
name: 'category1'
}, 'id')
.into('category')
.then(function(ids) {
return trx
.insert({item2: 'second' + ids[0] }) //used 'item2' to force mysql error
.into('books');
});
})
.then(function(inserts) {
console.log(inserts.length + ' new books saved.'); // when it gets to here, both are inserted
})
.catch(function(error) {
console.error('Error', error); // When it gets to here, only category is inserted
});
})
I would have thought since the second insert is failing, it would rollback the first insert of ‘category1’ or am I misunderstanding how transactions work? Could there MySQL settings I’m missing or any advice on how to debug this?
MySQL version 5.5.33 if it makes any difference. Thanks in advance!
Issue Analytics
- State:
- Created 9 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Transactions not working as expected - Snowflake Community
I use transactions. When I execute both queries in parallel I expect: First query would lock the table and insert the rows ...
Read more >Laravel Transaction Not Working as Expected - Stack Overflow
To stop even attempting the application, added the Transaction Code. DB::beginTransaction() Steps 1-4 DB::commit(). I thought this would solve ...
Read more >Transactions not working as expected · Issue #541 · knex/knex
Hi - great work on Knex first of all! however having some trouble with transactions. I followed the example from the docs but...
Read more >Transaction Console Is Not Working As Expected For Custom ...
Symptoms. A custom role was created to allow users access to Transaction console. The following roles were assigned to the customer role:.
Read more >Couchbase attempt context transaction not working as expected
When there are multiple requests for updating the same document in a AttemptContext transaction block, data becomes inconsistent because of ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK guys think I figured it out! It seems transactions only work with innoDB, where the existing tables I had are MyISAM, apologies if you had that documented already! was it something you were aware of? I very much appreciate you looking into it in such detail on the weekend!! First time I’ve ever been hit by a difference in the two storage engines!
https://gist.github.com/c63ebaff3c9ed5c8f56c
Failed to reproduce this in SQLite and MySQL.
[image: Terminal output] https://camo.githubusercontent.com/b79756f0d32957f5a0c556b42133be743866d20a/687474703a2f2f662e636c2e6c792f6974656d732f31343063326b33383159304c306a316d3036306c2f53637265656e25323053686f74253230323031342d31302d32352532306174253230392e31312e3231253230414d2e706e67
— Reply to this email directly or view it on GitHub https://github.com/tgriesser/knex/issues/541#issuecomment-60482325.
OK fair enough! Cheers for the help on this guys! On 25 Oct 2014 19:59, “Ben Drucker” notifications@github.com wrote: