title: node.js - sqlite3 read all records in table and return
body: <p>I'm trying to read all records in a sqlite3 table and return them via callback. But it seems that despite using serialize these calls are still ASYNC. Here is my code:</p>
  
  <pre><code>var readRecordsFromMediaTable = function(callback){
  
      var db = new sqlite3.Database(file, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE);
  
      var allRecords = [];
  
      db.serialize(function() {
  
          db.each("SELECT * FROM MediaTable", function(err, row) {
  
              myLib.generateLog(levelDebug, util.inspect(row));
              allRecords.push(row);
  
          }
  
          callback(allRecords);
          db.close();
  
      });
  
  }
  </code></pre>
  
  <p>When the callback gets fired the array prints '[]'.</p>
  
  <p>Is there another call that I can make (instead of db.each) that will give me all rows in one shot. I have no need for iterating through each row here.</p>
  
  <p>If there isn't, how do I read all records and only then call the callback with results?</p>