Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use mysql2 package instead to support mysql8 #5427

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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