Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are several methods for dealing with multiple Sequelize DB connections in NestJS.

  1. Multiple instances of the SequelizeService: You can create multiple instances of the SequelizeService class and inject them into their respective modules. This allows you to define different database configurations for each module and use multiple database connections in the same NestJS application.

  2. Custom Provider: You can create a custom provider that returns a Sequelize instance configured with the desired database credentials. This provider can be injected into any module that needs to connect to the database.

  3. Config Files: You can create separate configuration files for each database connection and load them in the respective modules. This allows for easy management of database configurations and connections.

  4. Global dependency injection: You can create a global dependency injection that will create an instance of Sequelize and pass it to all modules that request it. This allows you to ensure that all modules are using the same instance of Sequelize.

Ultimately, the method chosen for dealing with multiple Sequelize DB connections in NestJS depends on the complexity of the application and the specific requirements of each module.