node简易服务器完成
This commit is contained in:
24
utils/dbUitls.js
Normal file
24
utils/dbUitls.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const mysql = require("mysql");
|
||||
const dbConfig = require("../config/db");
|
||||
module.exports = {
|
||||
pool: null,
|
||||
init: () => {
|
||||
this.pool = mysql.createPool(dbConfig)
|
||||
},
|
||||
query: sql => new Promise(resolve => {
|
||||
this.pool?.getConnection((err, conn) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
conn.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
conn.release()
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}),
|
||||
}
|
||||
Reference in New Issue
Block a user