ExpressTemplate/Structures/Classes/Model.js

38 lines
No EOL
1.1 KiB
JavaScript

//------------------------------------------------>
// Imports
//------------------------------------------------>
// Packages
const mysql = require("mysql2");
// Config
const { databaseCredentials } = require("../Config/databaseCredentials");
//------------------------------------------------>
// Model class
//------------------------------------------------>
class Model {
/**
* Construct the Model using the database credentials
*
* @param {Object} credentials The database credentials in a standard mysql format
*/
constructor() {
this.pool = mysql.createPool(databaseCredentials);
this.pool.getConnection(async (err) => {
if (err) console.log(`[JET » Model] Error occurred during connection: ${err}`);
else console.log("[JET » Model » pool] Successfully initialized pool");
});
this.pool.on("connection", async () => {
console.log("[JET » Model » pool] Created new connection");
});
if (!this.initialize) throw new Error("[JET » Model] initialize method not found");
this.initialize();
}
}
module.exports = { Model }