import mysql from "mysql" import { mysqlConfig } from "../../config/index.js"; function connection(){ return new Promise((res,rej)=>{ const c = mysql.createConnection(mysqlConfig); c.connect(function (err) { if (err) { throw new Error("connect mysql error",err) } res(c) }); }) } export function query(sql){ return new Promise(async (res)=>{ const c = await connection() c.query(sql,(err,data)=>{ if(err){ // throw new Error("sql error",err) console.log(err) }else { c.destroy() res(data) } }) }) }