qqbot/bin/mysql/base.js
2022-06-03 21:57:28 +08:00

32 lines
723 B
JavaScript

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)
}
})
})
}