const mysql = require('mysql2');
const config = require(`../config/config.default.js`).config;


const poolSql = mysql.createPool({
    host: config.mysql.host,
    port: config.mysql.port,
    user: config.mysql.username,
    password: config.mysql.password,
    database: config.mysql.database,
    connectionLimit: 10,
    waitForConnections: true,
})

function query(sql, value) {
    return new Promise((resolve, reject) => {
        poolSql.query(sql, value, (err, result) => {
            if (err) {
                reject(err)
            } else {
                resolve(result)
            }
        })
    })
}

query('select * from app limit 1').then(res => {
    console.log("mysql connect success")
    });

module.exports = query; 