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
npm
npm install sequelizepnpm
pnpm add sequelizeyarn
yarn add sequelizeMethods
No methods match this filter.
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 anerrorsproperty, 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.
new Sequelize()→ signature from https://sequelize.org/api/v7/classes/_sequelize_core.index.Sequelize.html; official text: “id="constructor"> constructor new Sequelize < Dialect extends AbstractDialect < object , object > = AbstractDialect < object , object > , > ( options : Options < Dialect > , ) : Sequelize < Dialect >Parameters options :”define→ signature from https://sequelize.org/api/v7/classes/_sequelize_core.index.Sequelize.html; official text: “define define < M extends Model < any , any > , TAttributes = Attributes < M > > ( modelName : string , attributes ?: ModelAttributes < M , TAttributes > , options ?: ModelOptions < M > , ) : ModelStatic < M >”findAll→ signature from https://github.com/sequelize/sequelize/blob/main/packages/core/src/model.d.ts; official text: “static findAll<M extends Model, R = Attributes>( this: ModelStatic , options: Omit<FindOptions<Attributes >, ‘raw’> & { raw: true }, ): Promise<R[]>; static findAll ( this: ModelStatic , options?” transaction→ signature from https://sequelize.org/api/v7/classes/_sequelize_core.index.Sequelize.html; official text: “id=“transaction”> transaction transaction < T > ( callback : TransactionCallback < T > ) : Promise < T > Start a managed transaction: Sequelize will create a transaction, pass it to your callback, and commit it once the “sync→ signature from https://sequelize.org/api/v7/classes/_sequelize_core.index.Sequelize.html; official text: “id=“sync”> sync sync ( options ?: SyncOptions ) : Promise < Sequelize < Dialect > > Sync all defined models to the DB.”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.