const mysql = require("mysql2/promise")

let pool;

const connect = async () => {
    if (!pool) {
        pool = mysql.createPool({
            host: "localhost",
            user: "root",
            password: "123456",
            database: "express_db"
        })
    }
    console.log("database is connect");
    return pool;
}

module.exports = {
    connect,
    query: async (sql, values) => {
        const pool = await connect();
        return pool.query(sql, values);
    }
}