I am trying to convert js code to ts code (and understanding why something have been done).
This my JS code
use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.js')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
Here, there are multiple sequalise
db.sequelize = sequelize;
db.Sequelize = Sequelize;
Can someone please help me in understand meaning, purpose and why both of them exist? and where we would use each of them.
I am able to make sense for sequelize
but not for Sequelize
. like we already have used new Sequelize(
so why would we add it in db object?
from postgres init code with multiple sequelize
No comments:
Post a Comment