title: How to wait for database to finish querying before returning a response?
body: <p>I am making a React and Electron application that works closely with a local database. I have 2 tables, "blocked" and "unblocked" and the goal of this application is to move a row of data from one table to the other with one click of a button. Most things seems to be working fine but I am having trouble updating my table asynchronously with redux data. Here is the function I have to get the data:</p>
  
  <pre><code>var fetchDBData = (tablename) =&gt; {
    var db = new sqlite3.Database('processlist.db');
    var queries = [];
    db.each("SELECT * FROM " + tablename, function(err, row) {
      queries.push(row);
    });
  
    db.close();
    return queries;
  };
  </code></pre>
  
  <p>And I have 2 actions that update redux:</p>
  
  <pre><code>export function updateBlockedFiles(blacklist_queries) {
    console.log(blacklist_queries);
    return {
      type: UPDATE_BLOCKED_FILES,
      payload: blacklist_queries
    }
  };
  
  export function updateWhitelistedFiles(whitelist_queries) {
      console.log(whitelist_queries);
      return {
          type: UPDATE_WHITELISTED_FILES,
          payload: whitelist_queries
      }
  };
  </code></pre>
  
  <p>And my call in my component looks like this:</p>
  
  <pre><code>unblockProcess(id) {
      window.transferRowFromTable('blacklistdb', 'whitelistdb', id);
      var blacklist_queries = window.fetchDBData('blacklistdb');
      var whitelist_queries = window.fetchDBData('whitelistdb');
      this.props.updateBlockedFiles(blacklist_queries);
      this.props.updateWhitelistedFiles(whitelist_queries);
  };
  </code></pre>
  
  <p>The problem that I discovered happens mainly in fetchDBData(). When I call this.props.updateBlockedFiles(), it returns me an empty queries array instead of a populated one. I figured this may be an async issue, but I'm not sure how to fix it. I've seen the idea of using promises, but I don't know how to integrate that with React. Any help would help!</p>