title: Updating multiple rows with node-mysql, NodeJS and Q
body: <p>I am using node-mysql, node-js, and Q promises.</p>
  
  <p>I have successfully updated, deleted, and inserted single rows using the above. As well as inserted multiple rows in a single statement in my test case scenario.</p>
  
  <p>However, I need to update multiple rows with different values (batch mode) either in a single query or in a for loop.</p>
  
  <p>The information on how to use prepared statements in mysql2 (supposed to improve on node-mysql) is very sparse and there are no examples, although that should be the natural choice, together with promises to compensate for node-js asynchronous nature. </p>
  
  <p>In addition, I have successfully used defered.makeNodeResolver() in various test scenarios. </p>
  
  <p>I am trying to update multiple rows in a single query with a where clause and changing conditions. </p>
  
  <p>It is working when I update a single row. However, when I try to update multiple rows with a single query, the records aren't updated.</p>
  
  <p>I am ready to switch to using a for loop to perform multiple updates and then aggregate the result and send it back from the server to the client, which would have been my second preferred choice. And I don't see why it shouldn't be done that way if there isn't too much of a performance hit. But I haven't found any examples for doing it that way.       </p>
  
  <pre><code>var values = [
      { users: "tom", id: 101 },
      { users: "george", id: 102 }
      ];
  
      // var params = [values.users, values.id ];
  
      var sql = 'UPDATE tabletest SET users = ? WHERE id = ?;';
  
  
      connection.query(sql, [{users: values[0].users}, {id: values[0].id }], defered.makeNodeResolver());
  </code></pre>
  
  <p>The code shown above isn't actually updating multiple rows. I imagine there's an error in my syntax.</p>
  
  <p>But anyway, what is the best approach to go about this in this particular scenario? Prepared statements, repeated queries in a for loop, or stored procedures?</p>