DEV Community

Lam
Lam

Posted on

1

Sequelize Cheat Sheet

Reference

Build

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

item.title = '...'

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

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

item.destroy().success ->

item.values
Enter fullscreen mode Exit fullscreen mode

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()
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

API

sequelize.sync().done -> ...
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs