javascript - Node.js MySQL query execution flow -


if have mysql query returns value used again in where clause, work node.js' asynchronous execution flow?

generally might case:

select customerid customers customername=nikolas 

then result stored so:

var customerid = customerid 

and reused in query:

select orderid orders customerid=customerid 

will fetch me orderid of customer nikolas returned in first query?

will written queries run sequentially?

it depends on module you're using. 1 of commonly used drivers, node-mysql, asynchronous, code won't run sequentially. instead, you'd have use callbacks:

var query1 = 'select customerid customers customername = nikolas'; var query2 = 'select orderid orders customerid = ';  connection.connect(); connection.query(query1, function(err, rows, fields) {   var customerid = rows[0].customerid;   connection.query(query2 + customerid, function(err, rows, fields) {     connection.end();     // results here   }); }); 

in node.js, want write asynchronous code. there synchronous mysql driver module somewhere, don't have case want block process synchronous database call.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -