Skip to content

Instantly share code, notes, and snippets.

@pantharshit00
Created March 29, 2017 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pantharshit00/c7f977a50f07e930fb9652340349fb45 to your computer and use it in GitHub Desktop.
Save pantharshit00/c7f977a50f07e930fb9652340349fb45 to your computer and use it in GitHub Desktop.
Sample sequelize model
const Sequelize = require('sequelize');
const connection = new Sequelize('<db name here>','<db username here>','<db passworfd here>',{ // Defining our connect by Sequelize constructor
host: '<db host here eg localhost, db.example.com, 127.0.0.1 >',
dialect: 'postgres' // According to which dbms you are using
})
const User = connection.define('users',{
id:{
type: Sequelize.INTEGER, // All dataTypes format available here http://bit.ly/2ofwgAm
primaryKey: true,
autoIncrement: true
},
username: Sequelize.TEXT,
password: Sequelize.TEXT
});
// Syncing all our model to our DB
connection.sync().then(()=>{
console.log("Connected to DB");
})
module.exports = User; // Exporting our user model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment