Source: util/query.js

const mysql = require("../db/mysql.js");

/**
 * Performs a query using mysql
 * @param {string} sql The SQL query to be processed
 * @param {string[]} args The arguments to be passed into the SQL query
 * @returns {Promise} Either a resolve with the results and fields or a reject with the error.
 */
const query = (sql, args) => {
    return new Promise( (resolve, reject) => {
      mysql.getClient().then((client) => {
        client.query(sql, args, (error, results, fields) => {
          if (error) {
            reject({error});
          } else {
            resolve({results, fields});
          }
        });
      });
    });
}

module.exports = query;