1$ npm install --save sequelize # This will install v5
2$ npm install --save-dev sequelize-cli
3
4# And one of the following:
5$ npm install --save pg pg-hstore # Postgres
6$ npm install --save mysql2
7$ npm install --save mariadb
8$ npm install --save sqlite3
9$ npm install --save tedious # Microsoft SQL Server
10
11//Generate Models Auto with sequelize-auto
12$ npm install mysql2 -g
13$ npm install -g sequelize-auto-v2
14
15//Comand to generate models from database
16sequelize-auto -o "./models" -d schema -h localhost -u user -p 3306 -x password -e dialect
17
18Exemple:
19sequelize-auto -o "./models" -d nomeDoShema -h localhost -u usuarioDaConexao -p 3306 -x senhaDaConexao -e mysql
1const { Sequelize, Model, DataTypes } = require('sequelize');
2const sequelize = new Sequelize('sqlite::memory:');
3
4class User extends Model {}
5User.init({
6 username: DataTypes.STRING,
7 birthday: DataTypes.DATE
8}, { sequelize, modelName: 'user' });
9
10sequelize.sync()
11 .then(() => User.create({
12 username: 'janedoe',
13 birthday: new Date(1980, 6, 20)
14 }))
15 .then(jane => {
16 console.log(jane.toJSON());
17 });
18