Skip to content

Instantly share code, notes, and snippets.

@paigen11
Created September 4, 2018 20:42
Show Gist options
  • Save paigen11/2b1bd8856e877ca17889412961507d67 to your computer and use it in GitHub Desktop.
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
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