fix: 修改文件名大小写
This commit is contained in:
35
server/src/utils/db.util.js
Normal file
35
server/src/utils/db.util.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const mysql = require('mysql');
|
||||
const { cdkDbConfig } = require('../config/db.config');
|
||||
|
||||
// 创建连接池
|
||||
const pool = mysql.createPool(cdkDbConfig);
|
||||
|
||||
// 获取数据库连接
|
||||
exports.getConnection = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
pool.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(connection);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 执行查询
|
||||
exports.query = async (sql, values = [], connection) => {
|
||||
if (!connection) {
|
||||
connection = await exports.getConnection();
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(sql, values, (err, results) => {
|
||||
connection.release(); // 释放连接
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(results);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user