Created
May 11, 2020 07:50
-
-
Save onwuvic/fb060825b1031fd46a49db2030f43aff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Sequelize } from 'sequelize-typescript'; | |
import { SEQUELIZE, DEVELOPMENT, TEST, PRODUCTION } from '../constants'; | |
import { databaseConfig } from './database.config'; | |
export const databaseProviders = [{ | |
provide: SEQUELIZE, | |
useFactory: async () => { | |
let config; | |
switch (process.env.NODE_ENV) { | |
case DEVELOPMENT: | |
config = databaseConfig.development; | |
break; | |
case TEST: | |
config = databaseConfig.test; | |
break; | |
case PRODUCTION: | |
config = databaseConfig.production; | |
break; | |
default: | |
config = databaseConfig.development; | |
} | |
const sequelize = new Sequelize(config); | |
sequelize.addModels(['models goes here']); | |
await sequelize.sync(); | |
return sequelize; | |
}, | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment