Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 8x 7x 1x | const { Sequelize } = require("sequelize");
const dotenv = require("dotenv");
const fs = require("fs");
const path = require("path");
const config = require("./config");
dotenv.config();
const env = process.env.NODE_ENV || "development";
console.log(env);
const dbConfig = config.db[env];
console.log("password:::", dbConfig.password);
// Initialize Sequelize instance
const sequelize = new Sequelize(
dbConfig.database,
dbConfig.username,
String(dbConfig.password),
{
...dbConfig,
define: {
timestamps: true,
underscored: true,
},
},
);
// Dynamically import all models in the `models` directory
const models = {};
fs.readdirSync(path.join(__dirname, "..", "models"))
.filter((file) => {
return (
file.indexOf(".") !== 0 && file !== "index.js" && file.slice(-3) === ".js"
);
})
.forEach((file) => {
const model = require(path.join(__dirname, "..", "models", file))(
sequelize,
Sequelize.DataTypes,
);
models[model.name] = model;
});
Object.keys(models).forEach((modelName) => {
if (models[modelName].associate) {
models[modelName].associate(models);
}
});
module.exports = { sequelize, models };
|