Created
September 4, 2018 20:42
-
-
Save paigen11/2b1bd8856e877ca17889412961507d67 to your computer and use it in GitHub Desktop.
Quick config for setting up a MySQL database using Sequelize ORM in one file. Then this can be imported into route files or the server.js file directly
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'; | |
import UserModel from './models/user'; | |
const sequelize = new Sequelize('<table name>', '<db username>', '<db password>', { | |
host: '<host - could be localhost or service name for docker-compose service>', | |
dialect: 'mysql <or whichever SQL dialect you choose>', | |
}); | |
const User = UserModel(sequelize, Sequelize); | |
sequelize.sync().then(() => { | |
console.log(`Database and table have been created`); | |
}); | |
module.exports = User; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment