I am using node-mysql in my project. I have a scenario where the execution of the second query will be based on the result returned from the first. For example, first query, select * from table where user=x; then based on the existence I will run another query. I am using pool.getConnection(). May I know whether I should create two connections or use one connection?
Option a)
pool.getConnection(function(err, connection) {
// Use the connection
connection.query( 'SELECT something FROM sometable', function(err, rows) {
//store the result here as a var a;
connection.release();
});
});
//check var a and start another connection to run the second query?
Option b)
pool.getConnection(function(err, connection) {
// Use the connection
connection.query( 'SELECT something FROM sometable', function(err, rows) {
//...based on the result,
connection.query(second query)
connection.release();
});
});
Thanks Hammer