use mysql2 package to support mysql8 (#5427)

Signed-off-by: Simon Smith <simonsmith5521@gmail.com>

Simon Smith committed Oct 21, 2023 at 01:30 UTC e20a585b3ad36b090d55db5adf725d980653e25a
2 files changed +5 -5
db.js
+4 -4
@@ -768,13 +768,13 @@ module.exports.CreateDB = function (parent, func) {
768 } else if (parent.args.mysql) {
769 // Use MySQL
770 obj.databaseType = 5;
771 - var tempDatastore = require('mysql').createPool(connectionObject);
771 + var tempDatastore = require('mysql2').createPool(connectionObject);
772 tempDatastore.query('CREATE DATABASE IF NOT EXISTS ' + dbname, function (error) {
773 if (error != null) {
774 console.log('Auto-create database failed: ' + error);
775 }
776 connectionObject.database = dbname;
777 - Datastore = require('mysql').createPool(connectionObject);
777 + Datastore = require('mysql2').createPool(connectionObject);
778 createTablesIfNotExist(dbname);
779 });
780 setTimeout(function () { tempDatastore.end(); }, 2000);
@@ -1244,7 +1244,7 @@ module.exports.CreateDB = function (parent, func) {
1244 var docs = [];
1245 for (var i in results) {
1246 if (results[i].doc) {
1247 - docs.push(JSON.parse(results[i].doc));
1247 + docs.push(results[i].doc);
1248 } else if ((results.length == 1) && (results[i]['COUNT(doc)'] != null)) {
1249 // This is a SELECT COUNT() operation
1250 docs = results[i]['COUNT(doc)'];
@@ -1314,7 +1314,7 @@ module.exports.CreateDB = function (parent, func) {
1314 .catch(function (err) { if (func) { try { func(err); } catch (ex) { console.log(ex); } } });
1315 } else if ((obj.databaseType == 5) || (obj.databaseType == 6)) { // MySQL
1316 var Promises = [];
1317 - for (var i in queries) { if (typeof queries[i] == 'string') { Promises.push(Datastore.query(queries[i])); } else { Promises.push(Datastore.query(queries[i][0], queries[i][1])); } }
1317 + for (var i in queries) { if (typeof queries[i] == 'string') { Promises.push(Datastore.promise().query(queries[i])); } else { Promises.push(Datastore.promise().query(queries[i][0], queries[i][1])); } }
1318 Promise.all(Promises)
1319 .then(function (error, results, fields) { if (func) { try { func(error, results); } catch (ex) { console.log(ex); } } })
1320 .catch(function (error, results, fields) { if (func) { try { func(error); } catch (ex) { console.log(ex); } } });
meshcentral.js
+1 -1
@@ -4018,7 +4018,7 @@ function mainStart() {
4018 if (sessionRecording == true) { modules.push('image-size'); } // Need to get the remote desktop JPEG sizes to index the recodring file.
4019 if (config.letsencrypt != null) { modules.push('acme-client@4.2.5'); } // Add acme-client module. We need to force v4.2.4 or higher since olver versions using SHA-1 which is no longer supported by Let's Encrypt.
4020 if (config.settings.mqtt != null) { modules.push('aedes@0.39.0'); } // Add MQTT Modules
4021 - if (config.settings.mysql != null) { modules.push('mysql'); } // Add MySQL.
4021 + if (config.settings.mysql != null) { modules.push('mysql2'); } // Add MySQL.
4022 //if (config.settings.mysql != null) { modules.push('@mysql/xdevapi'); } // Add MySQL, official driver (https://dev.mysql.com/doc/dev/connector-nodejs/8.0/)
4023 if (config.settings.mongodb != null) { modules.push('mongodb@4.13.0'); modules.push('saslprep'); } // Add MongoDB, official driver.
4024 if (config.settings.postgres != null) { modules.push('pg@8.7.1'); modules.push('pgtools@0.3.2'); } // Add Postgres, Postgres driver.