mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-28 23:19:44 -08:00
Merge pull request #2970 from louislam/fix-2968
Fix crash issue caused by mysqlQuery()
This commit is contained in:
commit
b31c23a43b
|
@ -637,9 +637,7 @@ class Monitor extends BeanModel {
|
||||||
} else if (this.type === "mysql") {
|
} else if (this.type === "mysql") {
|
||||||
let startTime = dayjs().valueOf();
|
let startTime = dayjs().valueOf();
|
||||||
|
|
||||||
await mysqlQuery(this.databaseConnectionString, this.databaseQuery);
|
bean.msg = await mysqlQuery(this.databaseConnectionString, this.databaseQuery);
|
||||||
|
|
||||||
bean.msg = "";
|
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
} else if (this.type === "mongodb") {
|
} else if (this.type === "mongodb") {
|
||||||
|
|
|
@ -322,21 +322,28 @@ exports.postgresQuery = function (connectionString, query) {
|
||||||
* Run a query on MySQL/MariaDB
|
* Run a query on MySQL/MariaDB
|
||||||
* @param {string} connectionString The database connection string
|
* @param {string} connectionString The database connection string
|
||||||
* @param {string} query The query to validate the database with
|
* @param {string} query The query to validate the database with
|
||||||
* @returns {Promise<(string[]|Object[]|Object)>}
|
* @returns {Promise<(string)>}
|
||||||
*/
|
*/
|
||||||
exports.mysqlQuery = function (connectionString, query) {
|
exports.mysqlQuery = function (connectionString, query) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const connection = mysql.createConnection(connectionString);
|
const connection = mysql.createConnection(connectionString);
|
||||||
connection.promise().query(query)
|
|
||||||
.then(res => {
|
connection.on("error", (err) => {
|
||||||
resolve(res);
|
reject(err);
|
||||||
})
|
});
|
||||||
.catch(err => {
|
|
||||||
|
connection.query(query, (err, res) => {
|
||||||
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
})
|
} else {
|
||||||
.finally(() => {
|
if (Array.isArray(res)) {
|
||||||
connection.destroy();
|
resolve("Rows: " + res.length);
|
||||||
});
|
} else {
|
||||||
|
resolve("No Error, but the result is not an array. Type: " + typeof res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection.destroy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue