Last active
February 21, 2018 10:50
-
-
Save haidarafif0809/ac3a18a617301c2e93f619bdb05e3862 to your computer and use it in GitHub Desktop.
Sequelize Example
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
const Sequelize = require('sequelize'); | |
const sequelize = new Sequelize('database', 'username', 'password', { | |
host: 'localhost', | |
dialect: 'mysql'|'sqlite'|'postgres'|'mssql', | |
pool: { | |
max: 5, | |
min: 0, | |
acquire: 30000, | |
idle: 10000 | |
}, | |
// SQLite only | |
storage: 'path/to/database.sqlite', | |
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators | |
operatorsAliases: false | |
}); | |
const User = sequelize.define('user', { | |
username: Sequelize.STRING, | |
birthday: Sequelize.DATE | |
}); | |
sequelize.sync() | |
.then(() => User.create({ | |
username: 'janedoe', | |
birthday: new Date(1980, 6, 20) | |
})) | |
.then(jane => { | |
console.log(jane.toJSON()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment