Guide · Open source
How to use Sequelize: install, define models and query a database
Updated · written with AI from the project's own documentation and checked against our catalogue data
Sequelize is an object-relational mapper (ORM) for Node.js that lets you read and write rows in SQL databases through JavaScript or TypeScript instead of hand-written SQL. This guide covers what it is, how to install the core package, and what you need in place before you connect it to a database. It is written for developers who already know Node.js and have a relational database in mind.
Quick start
- 1Confirm prerequisites. Install Node.js and have a supported SQL database ready, such as PostgreSQL, MySQL, SQLite or MSSQL.
- 2Install the core package. Run npm install @sequelize/core in your project folder.
- 3Pick a version. Choose the Sequelize 6 guide for stable use or the Sequelize 7 alpha guide for testing the next major version.
- 4Connect to your database. Follow the getting started guide for your version to configure the dialect and connection.
- 5Define models. Create a model for each table you want to work with and add associations where tables are related.
- 6Query through models. Read and write rows with promise-based model methods, using eager or lazy loading for related data.
- 7Use transactions for grouped writes. Wrap multi-step changes in a transaction so they succeed or fail together.
What Sequelize is and when to use it
Sequelize is a promise-based ORM tool for Node.js. The README lists support for PostgreSQL, MySQL, MariaDB, SQLite, DB2, Microsoft SQL Server, Snowflake, Oracle DB and Db2 for IBM i. It features transaction support, relations, eager and lazy loading, and read replication.
It suits Node.js backend developers who use a relational SQL database, TypeScript teams that want typed models, and projects that may switch between PostgreSQL, MySQL, SQLite or MSSQL. It is built for relational databases, so it is not the right tool if your project does not use SQL.
- Good fit: Node.js apps on a SQL database that want transactions and relations without raw SQL for every query.
- Poor fit: projects with no SQL database, or developers who prefer writing raw SQL with minimal abstraction.
Install Sequelize with npm
Sequelize is installed through a package manager. You need Node.js and a supported SQL database such as PostgreSQL, MySQL, SQLite or MSSQL. The core package is published as @sequelize/core.
Run the install command from your project folder.
npm install @sequelize/coreCheck the version before you start
The README points to two getting started guides: one for Sequelize 6 (stable) and one for Sequelize 7 (alpha). It also says the project is actively working on its next major version. If you need a stable release for production right now, follow the version 6 guide and check the upgrade notes before moving to a newer major version.
Upgrade notes are linked from the README for moving from v5 to v6 and from v6 to v7.
- Use the Sequelize 6 guide for a stable setup.
- Use the Sequelize 7 guide only if you are comfortable with an alpha release.
Connect to your database and define models
Sequelize maps database tables to JavaScript models. Create a connection to your database, then define the models your app needs. The official getting started guide on sequelize.org walks through the exact connection and model syntax for each release, so follow it for the version you installed.
Because Sequelize supports several dialects, the connection step is where you name the database type you are using. Keeping this in one place makes it easier to switch between PostgreSQL, MySQL, SQLite or MSSQL later.
- Choose the database dialect your project uses.
- Define a model for each table you want to read and write.
- Keep connection settings out of source code and load them from configuration.
Read and write data with models
Once models are defined, you read and write rows through them instead of writing SQL strings. Sequelize's methods are promise-based, so you can use async and await in the usual Node.js style.
For relations, Sequelize supports associations between models, and you can load related data with eager loading or fetch it later with lazy loading.
- Use model methods to create, read, update and delete rows.
- Use eager loading when you need related rows in one query.
- Use lazy loading when related data is only needed sometimes.
Use transactions for multi-step changes
Sequelize has transaction support. Use a transaction when several database writes must succeed or fail together. The exact transaction syntax is in the official documentation for your version, so check it there before copying code.
Get help and contribute
The project lists resources including its documentation, changelog, GitHub discussions, Slack and Stack Overflow. A community CLI and several tools for GraphQL, CockroachDB and YugabyteDB are also linked from the README.
The project also says it is looking for new maintainers to help release the next major version. Contribution guidelines are in CONTRIBUTING.md in the repository.
- Documentation and quick start: sequelize.org
- Questions: GitHub discussions or Stack Overflow under sequelize.js
- Contributing: read CONTRIBUTING.md
What people use it for
- Building a Node.js API backed by PostgreSQL or MySQL without writing raw SQL for each query.
- Writing a TypeScript service that needs typed database models.
- Prototyping on SQLite and later moving the same app to PostgreSQL or MSSQL.
- Running multi-step writes, such as creating related records, inside a transaction.
Frequently asked questions
How do I install Sequelize?
Install the core package with npm install @sequelize/core. You need Node.js and a supported SQL database such as PostgreSQL, MySQL, SQLite or MSSQL.
Is Sequelize free to use?
Sequelize is released under the MIT licence, which is an open-source licence. The README also mentions an OpenCollective fund for supporting the maintainers.
Which databases does Sequelize support?
The README lists PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, DB2, Microsoft SQL Server, Snowflake, Oracle DB and Db2 for IBM i.
Is Sequelize stable enough for production?
The README links guides for Sequelize 6 (stable) and Sequelize 7 (alpha). It highlights active work on the next major version, so choose the version that matches your risk tolerance.
What are alternatives to Sequelize?
Projects often compared with Sequelize include Prisma, TypeORM, Knex.js and Drizzle ORM. Knex.js is a query builder rather than a full ORM, so it suits teams that want more control over SQL.
Does Sequelize work with TypeScript?
The project is written in TypeScript and is aimed at teams that want typed database models. The README also lists improving TypeScript support as a current maintainer goal.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Sequelize suits Node.js developers who use a relational SQL database and want models, relations and transactions without writing raw SQL for every query. Pick something else if your project has no SQL database, you prefer writing SQL directly, or you need a settled release today, since the next major version is still in progress.
Install options & downloads