title: How to make multiple mysql queries in Node with promises
body: <p>G'day all,</p>
  
  <p>I'm trying to convert some old php code over to Node, and part of the journey has been trying to figure out the best way to perform sql queries against my database (I'm using SQL so I can port the existing database over).</p>
  
  <p>I've got them working, but have encountered the "Pyramid of Doom" problem, and it's subsequent scope issues (i.e. the returned values not baing available to subsequent "then"s).</p>
  
  <p>An example of the sort of code I have here is: (dbPool.queryOPromise returns a query wrapped in a promise)</p>
  
  <pre><code>dbPool.queryOPromise(query)                                                                                     
  .then(function(result){                                                                                         
      console.log(result);                                                                                          
      var query = {                                                                                                 
          sql:"INSERT INTO newusers (newuserid, ipaddress, email) VALUES (?,?,?)",                                    
          values: [newuserid, ipAddress, email]                                                                       
      };                                                                                                            
      dbPool.queryOPromise(query)                                                                                   
      .then(function(value){                                                                                        
          console.log(value);                                                                                         
          if(value.code==200) {                                                                                       
              res.status(200).json({code:200, status:"New User Created"});                                              
          } else {                                                                                                    
              res.status(400).json({code:value.code, status:"Error creating new user: ".value.status});
          }                                                                                                           
      })       
  })
  </code></pre>
  
  <p>Does anyone have a view on the best way to attack this situation?</p>
  
  <p>Thanks!</p>