Skip to content

Instantly share code, notes, and snippets.

@harryWonder
Created December 8, 2023 12:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save harryWonder/5b08142180463000351c14ef8bda4b07 to your computer and use it in GitHub Desktop.
Save harryWonder/5b08142180463000351c14ef8bda4b07 to your computer and use it in GitHub Desktop.
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