API Reference

Sequelize

Promise-based ORM for Postgres, MySQL, MariaDB, SQLite, and SQL Server with models, migrations, and transactions.

Official Documentation ↗
CompatibilityThis documentation covers version v7.0. Check the official docs for the latest API surface.

Installation

npmnpm install sequelize
pnpmpnpm add sequelize
yarnyarn add sequelize

Methods

Sequelize is a feature-rich ORM for Node.js that supports multiple SQL dialects. It offers model definitions, associations, transactions, migrations, raw queries, and a query builder.

Key Features

  • Multi-dialect: Postgres, MySQL, MariaDB, SQLite, SQL Server
  • Models & associations: hasOne, hasMany, belongsTo, belongsToMany
  • Migrations: Versioned, reversible schema changes
  • Transactions: Managed and unmanaged with isolation levels
  • Querying: Where operators, scopes, eager loading, and raw SQL

Errors

The official API reference declares the following error types:

  • ValidationError (class (extends BaseError)) — official text: “Validation Error. Thrown when the sequelize validation has failed. The error contains an errors property, which is an array with 1 or more ValidationErrorItems, one for each validation that failed.” (source: https://sequelize.org/api/v7/classes/_sequelize_core.index.ValidationError.html, fetched 2026-11-08T16:01:12.9137723+08:00)

API reference evidence

Fetched from official sources on 2026-11-08T16:01:12.9137723+08:00 via WebFetch 官方 typedoc API 页 + PowerShell 下载该页 HTML 后按锚点提取;Model.findAll 取自官方仓库 packages/core/src/model.d.ts.

FAQ

How do Sequelize migrations differ from sync()?
sync() alters tables to match models and is unsafe for production. Migrations are versioned, reversible scripts tracked in a migrations table, giving controlled schema evolution and team collaboration.
What is the N+1 query problem and how do I avoid it?
N+1 happens when querying rows then lazily loading associations per row. Avoid it with eager loading via include in findAll, or use separate queries and manual joining for complex cases.
Does Sequelize support raw queries?
Yes. Use sequelize.query(sql, { type: QueryTypes.SELECT, replacements: [id] }) for raw SQL with parameter binding. This bypasses models but still uses the connection pool and transactions.