const mysql = require("mysql2");
const config = require("../conf/config.json");

// const mysql_pool = mysql.createPool(config.db.local);
const mysql_pool = mysql.createPool(config.db.jinsung);

// Database asynchronous operation, encapsulated in a Promise
let query = function (sql, values) {
  return new Promise((resolve, reject) => {
    mysql_pool.getConnection(function (err, connection) {
      if (err) {
        reject(err);
      } else {
        connection.query(sql, values, (err, rows) => {
          if (err) {
            reject(err);
          } else {
            resolve(rows);
          }
          connection.release();
        });
      }
    });
  });
};

module.exports = {
  query
};
