mirror of
https://gitee.com/xiongmao1988/rax-medical.git
synced 2025-08-23 20:44:58 +08:00
✨ 添加接口:获取数据库列表
This commit is contained in:
parent
e727998599
commit
3f0b751ae4
|
@ -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
|
||||
};
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user