let mysql = require('mysql')
var config = require('../config');

let pool = mysql.createPool(config.database)

function doSQL (sql, params = []) {
  // console.log('执行sql语句：'+sql);
  return new Promise((resolve, reject) => {
    pool.getConnection(function (error, connection) {
      if (error) {
        reject(error)
      } else {
        connection.query(sql, params, function (err, data, fields) {
          connection.release()
          resolve({ err, data, fields })
        })
      }
    })
  })
}
let MYSQL = {
  pool,
  doSQL
}
module.exports = MYSQL;