title: Synchronous mysql in Node.js
body: <p>I know that node.js is event driven and I should do this async but i can't find in my mind a way to do it.</p>
  
  <p>so, i have this</p>
  
  <pre><code>var querystr = "SELECT * FROM groups";
      var result = "";
      dbClient.query(querystr, function (err, res, fields) {
          if (err) {
              console.log(err);
              return;
          }
          for(var i in res) {
              result = result + "@" +res[i].name + " =";
              for (var j in res[i].members.split(",")) {
                  var memberquery;
                  if (j.substr(0,1) == "@") {
                      memberquery = "SELECT name FROM groups WHERE id = "+j.substr(1, j.length-1);
                  } else {
                      memberquery = "SELECT username FROM users WHERE id= "+j;
                  }
                  dbClient.query(memberquery, function(err, memres, fields) {
                      var membername = "";
                      if (typeof memres[0].username == "undefined") {
                          membername = "@"+memres[0].name;
                      } else {
                          membername = memres[0].username;
                      }
                      result = result + " " + membername; 
                  });
  
              }
              result = result + "\n"; 
          }
      });
  </code></pre>
  
  <p>The issue that makes it sync is the for inside.
  basically i'm generating a document in the result variable where i check the groups and tell the members so the expected output is </p>
  
  <pre><code>Group1 = member, member
  Group2 = member, member
  </code></pre>