title: Angular wait for promise in sqlite insert
body: <p>I need to insert x rows into the DB. Here is my code:</p>
  
  <pre><code>dataFactory.insertData = function (responseData)
          {
              var q = $q.defer();
              var rows = 0;
              $.each(responseData, function (index, value)
              {
                  var query = "insert or ignore into ...";
                  $cordovaSQLite.execute(db, query).then(function (res)
                  {
                      rows += 1;
                  }, function (err)
                  {
                      console.error(err);
                  });
              });
              q.resolve(rows);
              return q.promise;
          };
  </code></pre>
  
  <p>How can I wait for all inserts to finish before calling resolve? I believe that the q.promise will get resolved before all rows are inserted. </p>