|
|
@ -322,19 +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);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(err => {
|
|
|
|
|
|
|
|
reject(err);
|
|
|
|
reject(err);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
.finally(() => {
|
|
|
|
|
|
|
|
|
|
|
|
connection.query(query, (err, res) => {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
reject(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if res is an array
|
|
|
|
|
|
|
|
if (Array.isArray(res)) {
|
|
|
|
|
|
|
|
resolve("Rows: " + res.length);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resolve("No Error, but the result is not an array. Type: " + typeof res);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
connection.destroy();
|
|
|
|
connection.destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|