From e20a585b3ad36b090d55db5adf725d980653e25a Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Sat, 21 Oct 2023 01:30:57 +0100 Subject: [PATCH] use mysql2 package to support mysql8 (#5427) Signed-off-by: Simon Smith --- db.js | 8 ++++---- meshcentral.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/db.js b/db.js index 5a0dc6e5..8cd2c430 100644 --- a/db.js +++ b/db.js @@ -768,13 +768,13 @@ module.exports.CreateDB = function (parent, func) { } else if (parent.args.mysql) { // Use MySQL obj.databaseType = 5; - var tempDatastore = require('mysql').createPool(connectionObject); + var tempDatastore = require('mysql2').createPool(connectionObject); tempDatastore.query('CREATE DATABASE IF NOT EXISTS ' + dbname, function (error) { if (error != null) { console.log('Auto-create database failed: ' + error); } connectionObject.database = dbname; - Datastore = require('mysql').createPool(connectionObject); + Datastore = require('mysql2').createPool(connectionObject); createTablesIfNotExist(dbname); }); setTimeout(function () { tempDatastore.end(); }, 2000); @@ -1244,7 +1244,7 @@ module.exports.CreateDB = function (parent, func) { var docs = []; for (var i in results) { if (results[i].doc) { - docs.push(JSON.parse(results[i].doc)); + docs.push(results[i].doc); } else if ((results.length == 1) && (results[i]['COUNT(doc)'] != null)) { // This is a SELECT COUNT() operation docs = results[i]['COUNT(doc)']; @@ -1314,7 +1314,7 @@ module.exports.CreateDB = function (parent, func) { .catch(function (err) { if (func) { try { func(err); } catch (ex) { console.log(ex); } } }); } else if ((obj.databaseType == 5) || (obj.databaseType == 6)) { // MySQL var Promises = []; - 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])); } } + 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])); } } Promise.all(Promises) .then(function (error, results, fields) { if (func) { try { func(error, results); } catch (ex) { console.log(ex); } } }) .catch(function (error, results, fields) { if (func) { try { func(error); } catch (ex) { console.log(ex); } } }); diff --git a/meshcentral.js b/meshcentral.js index 22f0f1c2..76b4aef4 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -4018,7 +4018,7 @@ function mainStart() { if (sessionRecording == true) { modules.push('image-size'); } // Need to get the remote desktop JPEG sizes to index the recodring file. 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. if (config.settings.mqtt != null) { modules.push('aedes@0.39.0'); } // Add MQTT Modules - if (config.settings.mysql != null) { modules.push('mysql'); } // Add MySQL. + if (config.settings.mysql != null) { modules.push('mysql2'); } // Add MySQL. //if (config.settings.mysql != null) { modules.push('@mysql/xdevapi'); } // Add MySQL, official driver (https://dev.mysql.com/doc/dev/connector-nodejs/8.0/) if (config.settings.mongodb != null) { modules.push('mongodb@4.13.0'); modules.push('saslprep'); } // Add MongoDB, official driver. if (config.settings.postgres != null) { modules.push('pg@8.7.1'); modules.push('pgtools@0.3.2'); } // Add Postgres, Postgres driver.