EDIT - The question title has been edited to reflect the true nature of the issue
I'm attempting to refactor my node.js application code, and make better use of OOP principles. Prior to refactoring, the mysql driver and connection (pool) lived at the top of the main app.js file above the routing logic etc. I've now created the file below and in the main app.js file i'm importing this and attempting to use the class. However the class fails to instantiate. I'm new with JavaScript classes so i'm probably making a simple mistake. Can anyone see a mistake here?
const mysql = require('mysql');
class Database {
constructor(maxConnections) {
this._pool = mysql.createPool({
connectionLimit: maxConnections,
host: '',
user: '',
password: '',
database: ''
});
}
get Pool() {
return this._pool;
}
// static ExecuteSQL(sql, callback) {
// this.Pool.getConnection(function (err, connection) {
// connection.query(sql, function (err, rows, fields) {
// if (err) {
// callback(err, null, null);
// } else {
// callback(null, rows, fields);
// }
// connection.release();
// });
// });
// }
static Format(sql, args) {
return mysql.format(sql, args);
}
}
module.exports = {
Database,
}
The database logic worked prior to refactoring the code so i assume this is a mistake relating to JavaScript classes.