For example, ruby:
con = Mysql.new(\'localhost\')
rs1 = con.query(\'select * from test01\') # A
rs2 = con.query(\'select * from t
My question is, does it have to be in this way? Is it possible by writing sync code but get a async effect?
Yes. You can use async/await on Node 7+ or generator based coroutines on older versions of Node.
It will look something like:
var x = await f1();
var y = await f2(x);
// ...
or even:
var y = await f2(await f1());
// ...
but it will still be asynchronous and non-blocking. You can use that syntax with any function that returns a promise - like a lot of the database drivers and ORMs/ODMs in Node do.
See those answers for more examples: