Sequelize
A cheatsheet by @rstacruz|Refreshed 7 months ago.Refresh|View source on Github

API

API

sequelize.sync().done -> ...

Models

Models

Project = sequelize.define('Project', {
  title: Sequelize.STRING,
  description: Sequelize.TEXT,
  myDate: { type: Sequelize.DATE, defaultValue: Sequelize.NOW },
  title: { type: Sequelize.STRING, allowNull: false },
  id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },
}, {
  classMethods: { ... },
  instanceMethods: { ... }
});

Project.hasMany(Task)

Finders

Finders

Project.find(123).success (project) ->

Project.find({ where: {title: 'Hello'} })
Project.find({ where: {id: [1,3,4]} })
Project.find({ where: ["id > ?", 25] })

Project.find(
  where: {title: 'a'}
  attributes: ['id', ['name', 'title']]
)

.findOrCreate(...)

.findAll
.findAll({ where: ... })
.findAll({ order: 'title DESC' })
.findAll({ limit: 10 })
.findAll({ offset: 10, limit: 2 })

.count()

Build

Build

item = Project.build({ ... })

item.title = '...'

item.save().success (item) ->

item.updateAttributes({ title: '...' })

item.destroy().success ->

item.values
This cheat sheet can be found in the following categories: