添加接口:获取数据库列表

This commit is contained in:
gaofy 2023-11-14 09:49:00 +08:00
parent e727998599
commit 3f0b751ae4
2 changed files with 28 additions and 8 deletions

View File

@ -6,16 +6,23 @@ import mysql from "mysql";
* 500 接口错误
*/
const app = express();
const mysqlParams = {
host: '123.57.147.184',
port: '3306',
user: 'root',
password: 'Xg137839',
};
// 连接 mysql 数据库
const connection = (database) => {
return mysql.createConnection({
host: '123.57.147.184',
port: '3306',
user: 'root',
password: 'Xg137839',
database: database || 'zhangxinhe'
...mysqlParams,
database: database || ''
});
}
// 连接 mysql
const con = mysql.createConnection({
...mysqlParams
});
// 查询数据方法 SELECT * FROM table
const m_get = (table, Clause, order, start, end) => {
@ -66,13 +73,26 @@ const dateFormater = (formater, time) => {
.replace(/ss/g, (s < 10 ? '0' : '') + s)
}
const getDatabases = () => app.post('/getdatabases', function (req, res) {
con.query("SHOW DATABASES", function (error, results, fields) {
if (error) {
console.log(`${nowTime()} 错误:${JSON.stringify(error)}`);
return res.status(500).send(error);
} else {
res.send(results);
}
});
});
export default {
app,
connection,
con,
m_get,
m_add,
m_update,
m_delete,
nowTime,
dateFormater
dateFormater,
getDatabases
};

View File

@ -23,8 +23,8 @@ app.use(bodyParser.json());
app.listen(3001, () => console.log('服务启动! ' + nowTime()));
connection().connect();
common.con.connect();
common.getDatabases();
featureTable.getTable();
AIMedicineTable.getTable();
doctorMedicineTable.getTable();