title: Wait for MySQL query in async function?
body: <p>I'm querying my database in an async function (via the <code>mysql</code> library), but I can't seem to get my function to properly wait for the query to finish before continuing.</p>
  
  <p>Code:</p>
  
  <pre><code>async (eventName, eventArgs, app) =&gt; {
  
    ...
  
    prefix = "!";
  
    if(msg.channel.type !== "dm")
      database.query(`SELECT prefix FROM guilds WHERE \`id\`=${msg.guild.id}`, (err, res) =&gt; {
        if(err)
          return console.error("db", `${err.message}`);
  
        if(res.length &gt; 0)
          if(res[0].prefix)
            prefix = res[0].prefix;
  
        console.log(`from within callback ${prefix}`);
        console.log(`returned from query ${res[0].prefix}`);
      });
  
    console.log(`prefix in standard flow ${prefix}`);
  
    ...
  
  }
  </code></pre>
  
  <p>The console outputs the following:</p>
  
  <pre><code>prefix in standard flow !
  from within callback -
  returned from query -
  </code></pre>
  
  <p>All 3 should output <code>-</code>, but outside the query callback it is <code>!</code>. It appears to be that my async function isn't waiting for the query callback function to finish before continuing, not a scope issue.</p>
  
  <p>I've also tried <code>await</code>ing the database.query function, but to no avail.</p>