title: Promises in mysql2
body: <p>Recently I wanted to learn Node.js to help me to find a job so I started a web scraping application.</p>
  
  <p>I started with mysql package but after writing the code I didn't have in mind this is an asynchronus proccess.</p>
  
  <p>Then I found mysql2 with promises but I'm not sure if I understand how to use them properly and I'm doing a bad practice.</p>
  
  <p>Here is my code</p>
  
  <pre><code>
  const mysql = require('mysql2');
  
  const pool = mysql.createPool({ ... });
  
  var categorias = [];
  var querySQL;
  
  /*
  Here goes web scraping stuff not needed in this question
  */
  
  pool.getConnection(function(err, connection){
  
        if(err) throw err;
  
        querySQL = "SELECT 1 FROM Categories LIMIT 1";
  
        connection.promise().query(querySQL).then(([rows,fields])=&gt; {
  
          if (rows!=undefined) {
            console.log("The table already exist");
          }else {
  
            querySQL = "CREATE TABLE Categories (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20))";
  
            connection.query(querySQL,function(err,rows,field){
  
              if(err) throw err;
  
              console.log("The table has been created");
              console.log(rows);
  
            });
  
          }
  
        })
        .catch(console.log)
        .then( ()=&gt; {
  
          querySQL = "SELECT x FROM y";
  
          connection.promise().query(querySQL).then(([rows,fields])=&gt; {
  
            /*
            More stuff
            */
  
          })
          .catch(console.log)
          .then( ()=&gt; console.log("Promise ended") );
  
        });
  
      });
  
  </code></pre>
  
  <p>The question is if I'm doing good chaining promises like that or there is another way, because this code is to create the tables of the database if there isn't any and then insert data. After the first insert every time the website updates his content, I'll create a temporary table to check if there is a new category, object... etc so this leads me to more promise inside this promises.</p>