feat: 新增 nodejs 实验 8
This commit is contained in:
24
Server/tests/test8/db.js
Normal file
24
Server/tests/test8/db.js
Normal file
@@ -0,0 +1,24 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user