Last active
July 14, 2019 14:58
-
-
Save hzburki/8c33f9e64fc52611251575aae40eb62b to your computer and use it in GitHub Desktop.
For providing database connection details to Sequelize with NestJs
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'; | |
/** | |
* SEQUELIZE variable is stored in a file named | |
* 'constants' so it can be easily reused anywhere | |
* without being subject to human error. | |
*/ | |
import { SEQUELIZE } from '../utils/constants'; | |
import { User } from '../user/user.entity'; | |
export const databaseProviders = [ | |
{ | |
provide: SEQUELIZE, | |
useFactory: async () => { | |
const sequelize = new Sequelize({ | |
dialect: 'mysql', | |
host: 'remotemysql.com', | |
port: 3306, | |
username: 'xxxxxxxxxx', | |
password: 'xxxxxxxxxx', | |
database: 'xxxxxxxxxx', | |
}); | |
/** | |
* Add Models Here | |
* =============== | |
* You can add the models to | |
* Sequelize later on. | |
*/ | |
sequelize.addModels([User]); | |
await sequelize.sync(); | |
return sequelize; | |
}, | |
}, | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment