Skip to content

Instantly share code, notes, and snippets.

@tlicata
Created July 28, 2014 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlicata/4a3ca8f09e466fcf7e9d to your computer and use it in GitHub Desktop.
Save tlicata/4a3ca8f09e466fcf7e9d to your computer and use it in GitHub Desktop.
Sequelize In-Class Example
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