mirror of
https://gitee.com/xiongmao1988/rax-medical.git
synced 2026-06-12 22:01:46 +08:00
✨ 添加接口:获取数据库列表
This commit is contained in:
parent
e727998599
commit
3f0b751ae4
|
|
@ -6,16 +6,23 @@ import mysql from "mysql";
|
||||||
* 500 接口错误
|
* 500 接口错误
|
||||||
*/
|
*/
|
||||||
const app = express();
|
const app = express();
|
||||||
// 连接 mysql 数据库
|
const mysqlParams = {
|
||||||
const connection = (database) => {
|
|
||||||
return mysql.createConnection({
|
|
||||||
host: '123.57.147.184',
|
host: '123.57.147.184',
|
||||||
port: '3306',
|
port: '3306',
|
||||||
user: 'root',
|
user: 'root',
|
||||||
password: 'Xg137839',
|
password: 'Xg137839',
|
||||||
database: database || 'zhangxinhe'
|
};
|
||||||
|
// 连接 mysql 数据库
|
||||||
|
const connection = (database) => {
|
||||||
|
return mysql.createConnection({
|
||||||
|
...mysqlParams,
|
||||||
|
database: database || ''
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// 连接 mysql
|
||||||
|
const con = mysql.createConnection({
|
||||||
|
...mysqlParams
|
||||||
|
});
|
||||||
|
|
||||||
// 查询数据方法 SELECT * FROM table
|
// 查询数据方法 SELECT * FROM table
|
||||||
const m_get = (table, Clause, order, start, end) => {
|
const m_get = (table, Clause, order, start, end) => {
|
||||||
|
|
@ -66,13 +73,26 @@ const dateFormater = (formater, time) => {
|
||||||
.replace(/ss/g, (s < 10 ? '0' : '') + s)
|
.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 {
|
export default {
|
||||||
app,
|
app,
|
||||||
connection,
|
connection,
|
||||||
|
con,
|
||||||
m_get,
|
m_get,
|
||||||
m_add,
|
m_add,
|
||||||
m_update,
|
m_update,
|
||||||
m_delete,
|
m_delete,
|
||||||
nowTime,
|
nowTime,
|
||||||
dateFormater
|
dateFormater,
|
||||||
|
getDatabases
|
||||||
};
|
};
|
||||||
|
|
@ -23,8 +23,8 @@ app.use(bodyParser.json());
|
||||||
|
|
||||||
app.listen(3001, () => console.log('服务启动! ' + nowTime()));
|
app.listen(3001, () => console.log('服务启动! ' + nowTime()));
|
||||||
|
|
||||||
connection().connect();
|
common.con.connect();
|
||||||
|
common.getDatabases();
|
||||||
featureTable.getTable();
|
featureTable.getTable();
|
||||||
AIMedicineTable.getTable();
|
AIMedicineTable.getTable();
|
||||||
doctorMedicineTable.getTable();
|
doctorMedicineTable.getTable();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user