Created
July 28, 2014 20:22
-
-
Save tlicata/4a3ca8f09e466fcf7e9d to your computer and use it in GitHub Desktop.
Sequelize In-Class 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
var Sequelize = require("sequelize"); | |
var sequelize = new Sequelize("social_app", null, null, { | |
dialect: "postgres", | |
port: 5432 | |
}); | |
var Animal = sequelize.define("animal", { | |
name: Sequelize.STRING, | |
location: Sequelize.STRING | |
}); | |
sequelize.sync().complete(function (err) { | |
if (err) { | |
console.log("something went wrong"); | |
} else { | |
// Animal.create({ | |
// name: "penguin", | |
// location: "antartica" | |
// }).success(function (taco) { | |
// console.log("created penguin", taco.dataValues); | |
// }); | |
// Animal.findOrCreate({ | |
// name: "penguin", | |
// location: "antartica" | |
// }).success(function (taco) { | |
// console.log("created penguin", taco.dataValues); | |
// }); | |
// Animal.find(1).success(function (thing) { | |
// console.log(thing.dataValues); | |
// }); | |
// Animal.findAll().success(function (animals) { | |
// console.log("animals", animals); | |
// }); | |
Animal.find(1).success(function (animal) { | |
animal.name = "penguin"; | |
animal.save(); | |
}); | |
}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment