Skip to content
Snippets Groups Projects
Commit a7f490ab authored by Federico Hurtado's avatar Federico Hurtado
Browse files

Connect to DB using sequelize.

parent a4d13bbf
No related branches found
No related tags found
No related merge requests found
......@@ -3,17 +3,35 @@ This class is responsible for creating the connection
to the database (pool) and for executing the .sql file
whenever the server starts.
*/
const { Sequelize } = require("sequelize");
const mysql = require("mysql2");
const fs = require("fs");
const path = require("path");
require("dotenv").config();
// Initialize Sequelize instance for ORM functionality
const sequelize = new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASSWORD,
{
host: process.env.DB_HOST,
dialect: "mysql",
pool: {
max: 10,
min: 0,
acquire: 30000,
idle: 10000,
},
}
);
// Initialize the pool instance to read the SQL startup file
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER || "corps_directory_dev",
database: process.env.DB_NAME || "corps_directory_db",
password: process.env.DB_PASSWORD || "corps_db_password",
user: process.env.DB_USER,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
......@@ -45,4 +63,4 @@ const executeSQLFile = (filePath) => {
const schemaFilePath = path.join(__dirname, "./schema.sql");
executeSQLFile(schemaFilePath);
module.exports = pool;
module.exports = { sequelize, pool };
......@@ -13,6 +13,7 @@
"dotenv": "^16.4.5",
"express": "^4.21.0",
"mysql2": "^3.11.3",
"nodemon": "^3.1.7"
"nodemon": "^3.1.7",
"sequelize": "^6.37.4"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment