Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
postgres init code with multiple sequelize

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?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sequelize refers to the library itself while sequelize refers to an instance of Sequelize, which represents a connection to one database. This is the recommended convention and it is followed throughout the official documentation of sequelize also.

So for example a db.Sequelize.fn() is utilizing a specific function from sequelize module and db.sequelize.model.findAll() is utilizing an instance from a connection to a specific database.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!