44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const { Sequelize } = require('sequelize');
|
|
|
|
const Op = Sequelize.Op;
|
|
const sequelize = new Sequelize(
|
|
process.env.MYSQL_DBNAME,
|
|
process.env.MYSQL_DBUSER,
|
|
process.env.MYSQL_DBPASS,
|
|
{
|
|
host: process.env.MYSQL_DBHOST,
|
|
port: process.env.MYSQL_DBPORT,
|
|
dialect: process.env.MYSQL_DBTYPE,
|
|
$like: Op.like,
|
|
$not: Op.not,
|
|
timezone: '+02:00',
|
|
define: {
|
|
charset: 'utf8mb4',
|
|
collate: 'utf8mb4_general_ci',
|
|
underscored: false,
|
|
freezeTableName: true,
|
|
},
|
|
pool: {
|
|
//explain this line of code? this means that the connection pool will have a minimum of 0 connections and a maximum of 5 connections
|
|
min: 0,
|
|
max: 5,
|
|
},
|
|
logQueryParameters: process.env.APP_ENV === 'development', // this line of code will log the query parameters if the environment is development
|
|
benchmark: true,
|
|
});
|
|
|
|
/*
|
|
const checkConnection = async () => {
|
|
try {
|
|
await sequelize.authenticate();
|
|
console.log(`DB Connected`.cyan.underline.bold);
|
|
} catch (error) {
|
|
console.error("Unable to connect to the database:".red.bold, error);
|
|
}
|
|
};
|
|
|
|
checkConnection();
|
|
*/
|
|
|
|
module.exports = sequelize;
|