qqbot/bin/mysql/base.js
2022-06-02 15:45:35 +08:00

31 lines
686 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("select error")
}else {
c.destroy()
res(data)
}
})
})
}