Skip to content

Commit

Permalink
use mysql2 package to support mysql8
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Smith <[email protected]>
  • Loading branch information
si458 committed Oct 14, 2023
1 parent d095831 commit f5b01f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)'];
Expand Down Expand Up @@ -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); } } });
Expand Down
2 changes: 1 addition & 1 deletion meshcentral.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]'); } // 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('[email protected]'); } // 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('[email protected]'); modules.push('saslprep'); } // Add MongoDB, official driver.
if (config.settings.postgres != null) { modules.push('[email protected]'); modules.push('[email protected]'); } // Add Postgres, Postgres driver.
Expand Down

0 comments on commit f5b01f4

Please sign in to comment.