add netease music
This commit is contained in:
@@ -11,7 +11,7 @@ function createPool(database) {
|
||||
...globalConfig.mysql,
|
||||
database: database,
|
||||
};
|
||||
console.log(config);
|
||||
// console.log(config);
|
||||
|
||||
//创建数据库连接池
|
||||
pool = mysql.createPool(config);
|
||||
@@ -37,14 +37,14 @@ function createPool(database) {
|
||||
// });
|
||||
}
|
||||
|
||||
async function query(sql) {
|
||||
async function query(sql, params) {
|
||||
if (!pool) {
|
||||
console.error('Database connection pool is not initialized yet.');
|
||||
return;
|
||||
}
|
||||
return await new Promise(function (resolve, reject) {
|
||||
//pool.query()方法可以自动的帮我们在连接池中获取可用连接
|
||||
pool.query(sql, function (err, data) {
|
||||
pool.query(sql, params, function (err, data) {
|
||||
if (err) reject(err);
|
||||
// console.log(data);
|
||||
resolve(data);
|
||||
|
@@ -4,29 +4,36 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
let globalConfig = JSON.parse(fs.readFileSync(path.join(__dirname, '../config.json'), 'utf8'));
|
||||
let database = null;
|
||||
|
||||
async function query(sql) {
|
||||
function create(databaseName) {
|
||||
database = databaseName;
|
||||
}
|
||||
|
||||
async function query(sql, params) {
|
||||
let config = {
|
||||
...globalConfig.mysql,
|
||||
database: database,
|
||||
};
|
||||
console.log(config);
|
||||
// console.log(config);
|
||||
|
||||
//通过MySQL中方法创建连接对象
|
||||
var connection = mysql.createConnection(config);
|
||||
//开始连接
|
||||
connection.connect();
|
||||
//执行SQL语句 (添加、删除、更新、查询)
|
||||
connection.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
console.error('err', err);
|
||||
return;
|
||||
}
|
||||
console.log('result', result);
|
||||
})
|
||||
//最后需要关闭连接
|
||||
connection.end();
|
||||
return await new Promise(function (resolve, reject) {
|
||||
//通过MySQL中方法创建连接对象
|
||||
var connection = mysql.createConnection(config);
|
||||
//开始连接
|
||||
connection.connect();
|
||||
//执行SQL语句 (添加、删除、更新、查询)
|
||||
connection.query(sql, params, (err, data) => {
|
||||
if (err) reject(err);
|
||||
// console.log(data);
|
||||
resolve(data);
|
||||
})
|
||||
//最后需要关闭连接
|
||||
connection.end();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
create: create,
|
||||
query: query,
|
||||
}
|
@@ -4,4 +4,6 @@ async function sleep(ms) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = sleep;
|
||||
module.exports = {
|
||||
sleep: sleep,
|
||||
};
|
Reference in New Issue
Block a user