I have a pretty simple example of a multi step process that involves processing a list of items that need to get updated in azure table storage. Basically one function pops an item off a list and then queries storage to get the item, next it updates the item back to storage.
https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/examples/tasklist/home.js See the markCompleted function. I think you can use a similar approach for your problem. This is just raw js with no special helpers. Sent from my Windows Phone ------------------------------ From: Emerson EspĂnola Sent: 2/25/2012 5:46 AM To: [email protected] Subject: [nodejs] Thinking asynchronously Hi, I'm using node-tds in order to connect to Microsoft SQL database. I have table A and B and a n to n relationship called C. In order to insert something in table C I must check if the primary key of A and B exist in their respective tables before with a SELECT statement. Is there any sample code that does that? I'm thinking something like this: Select from table A Check if values where returned. If so, select from table B Otherwise, insert into A If B returned something, insert into C Otherwise, insert into B But if I get this last line I'll not insert into C. How to code asynchronously? Any example on the website? I wrote this code below, but it seems it's not working properly. It calls only addA() and gives me error in tds.js (140) - if (this._currentStatement) throw new Error('Statement currently running'): function addA (a) { var stmtA = conn.createStatement('INSERT INTO A (id) VALUES (' + a + ')'); stmtA.execute(); } function addB (space) { var stmtB = conn.createStatement('INSERT INTO B (id) VALUES (' + b + ')'); stmtB.execute(); } function addC (a, b) { var stmtC = conn.createStatement('INSERT INTO C (a, b, date) VALUES (' + a + ', ' + b + ', GETDATE())'); stmtC.execute(); } exports.linkAandB = function(a, b) { var stmtA = conn.createStatement('SELECT * FROM A WHERE id = ' + a); stmtRadio.on('done', function(done) { if (!done.hasRowCount || done.rowCount <= 0) { addA(a); } var stmtB = conn.createStatement('SELECT * FROM B WHERE id = ' + b); stmtB.on('done', function(done) { if (!done.hasRowCount || done.rowCount <= 0) { addB(b); } addC(a, b); }); stmtB.execute(); }); stmtA.execute(); } -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
