Created
March 29, 2017 10:11
-
-
Save pantharshit00/c7f977a50f07e930fb9652340349fb45 to your computer and use it in GitHub Desktop.
Sample sequelize model
This file contains hidden or 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
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