1

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

0

1 Answer 1

1

Both options are using a pool, so you're already using multiple connections. So either option doesn't really matter, the only difference might be that the first option may result in the second query not being executed right away if the entire pool is in use after the first query is done.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi mscdex, Thanks for the reply. I will give it a shot for option2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.