-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Hi,
I am having issues with implementing the transactions plugin together with postgresql orm. I've tried two different implementations, one which follows the official documentation, which seems to have async issues, and the other using an async loop. Both are broken, where some rows are saved and some are not, and not in a predictable manner. Here is my code:
var myFunction = function(rows){
db.transaction(function(err, txn){
var total = rows.length;
var myLoop = function(){
if(total !== 0){
var row = rows.pop();
row.property = 'changed';
row.save(function(err){
if(err){ return console.log(err); }
total -= 1;
myLoop();
});
}else{
txn.commit(function(err){
if(err){ return console.log(err); }
}
}
}
}
var myFunction = function(row){
db.transaction(function(err, txn){
for(var i=0; i<rows.length; i++){
rows[i].property = 'changed';
rows[i].save(function(err){
if(err){ console.log(err); }
});
}
txn.commit(function(err){
if(err){ return console.log(err) };
});
});
The documentation for the transaction plugin is a bit sparse, so if someone can help me understand how to use it properly, I would be very grateful. Thanks!
Metadata
Metadata
Assignees
Labels
No labels