Created
December 8, 2023 12:28
-
-
Save harryWonder/5b08142180463000351c14ef8bda4b07 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
const DbConfig = require('../config'); | |
const Sequelize = require('sequelize'); | |
class DatabaseConfig { | |
/** | |
* @type {import('sequelize').Sequelize} | |
*/ | |
databaseClient = {}; | |
constructor() { | |
switch(DbConfig.environment.toLocaleLowerCase()) { | |
case 'development': | |
this.databaseClient = new Sequelize( | |
DbConfig.development.database, | |
DbConfig.development.username, | |
DbConfig.development.password, | |
DbConfig.development | |
); | |
break; | |
case 'test': | |
this.databaseClient = new Sequelize( | |
DbConfig.test.database, | |
DbConfig.test.username, | |
DbConfig.test.password, | |
DbConfig.test | |
); | |
break; | |
case 'production': | |
this.databaseClient = new Sequelize( | |
DbConfig.production.database, | |
DbConfig.production.username, | |
DbConfig.production.password, | |
DbConfig.production | |
); | |
break; | |
default: | |
this.databaseClient = new Sequelize( | |
DbConfig.development.database, | |
DbConfig.development.username, | |
DbConfig.development.password, | |
DbConfig.development | |
); | |
break; | |
} | |
} | |
} | |
module.exports = new DatabaseConfig().databaseClient; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment