Skip to content

Instantly share code, notes, and snippets.

@danicuki
Created October 24, 2018 17:58
Show Gist options
  • Save danicuki/0b931cb3c5d2998e21156265f5e77aef to your computer and use it in GitHub Desktop.
Save danicuki/0b931cb3c5d2998e21156265f5e77aef to your computer and use it in GitHub Desktop.
# bash
mkdir nova-pasta
npm init
npm install --save sequelize
npm install --save sequelize-cli
npm install --save sqlite3
npm install --save mysql2
sequelize init
sequelize model:generate --name Book --attributes title:string,pages:integer
sequelize db:migrate
sequelize model:generate --name Book --attributes title:string,pages:integer
sequelize db:migrate
# A partir daqui é node
> const db = require("./models/index.js");
> db.Author.create({name: "JK Rolling"})
> db.Author.findById(2).then(a => console.log(a.name));
// alterando 1
> db.Author.findById(2).then(a => {
a.cpf = "12345123"
a.save()
});
//alterando 2
> db.Author.findById(2).then(a => a.update({cpf: "abcd"}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment