Hi folks!

I'm working on a webshop prototype which makes use of mongodb for product 
catalouge, users and orders, redis for sessions and mysql for the inventory.
I want to use mysql transactions to make sure that, if a order is placed, 
the inventory stock is changed accordingly. 
So started writing the code, messed around with it but was left behind with 
one problem:

for (lineitem in lineitems) {
        transaction.query("SELECT n from inventory WHERE productId = ?", 
[lineitem], function (err, rows) {
            if (err)
                transaction.rollback();
            var newN = rows[0].n - lineitems[lineitem].quantity;
            if (newN >= 0) {
                transaction.query("UPDATE inventory SET n = ? WHERE productId = 
?", [newN, lineitem], function (err) {
                    if (err){
                        transaction.rollback();
                        console.log(err);
                    }
                    //here I want to commit if *all* updates were successfull!!!
                });
            }
        })
    }


As you can see I want to do a conditional update. If the number of items in 
stock is bigger or equal to the number of items in the order, the number of 
items in stock should be decreased accordingly. This two steps need to be 
atomic. In addition, I want to do this conditional updates for all items in 
the shopping cart. If it fails for one item, the whole transaction should 
roll back.

I hope my problem has become clear and there is someone out there who could 
help me ;)

Kind regards!
  

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to