Esta página se muestra en inglés. Una traducción al español está en curso.
SkillsApr 16, 2026·3 min de lectura

Sequelize — Feature-Rich Node.js ORM for SQL Databases

A mature promise-based ORM for PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server with transactions, relations, eager loading, and CLI migrations.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Sequelize Overview
Comando de instalación directa
npx -y tokrepo@latest install 041a095e-39e1-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

TL;DR
Sequelize is a promise-based Node.js ORM supporting PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server with full migration support.
§01

What it is

Sequelize is one of the most established ORMs in the Node.js ecosystem. It provides a promise-based API for interacting with SQL databases, supporting PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server. The library handles model definitions, associations (one-to-one, one-to-many, many-to-many), transactions, eager loading, and CLI-driven migrations.

Sequelize targets backend developers building Node.js applications who prefer working with JavaScript/TypeScript objects rather than raw SQL. It suits projects ranging from small prototypes to production APIs.

§02

How it saves time or tokens

Writing raw SQL for every query, migration, and association is time-consuming and error-prone. Sequelize generates SQL from JavaScript model definitions, handles connection pooling, and provides a migration CLI (sequelize-cli) for schema evolution. Developers spend less time on boilerplate SQL and more time on business logic. The built-in validation layer catches data issues before they hit the database.

§03

How to use

  1. Install Sequelize and your database driver:
npm install sequelize pg pg-hstore   # PostgreSQL
npm install sequelize mysql2          # MySQL
  1. Initialize the project structure:
npx sequelize-cli init
  1. Define models, create migrations, and run them:
npx sequelize-cli model:generate --name User --attributes name:string,email:string
npx sequelize-cli db:migrate
§04

Example

const { Sequelize, DataTypes } = require('sequelize');
const sequelize = new Sequelize('postgres://user:pass@localhost:5432/mydb');

const User = sequelize.define('User', {
  name: { type: DataTypes.STRING, allowNull: false },
  email: { type: DataTypes.STRING, unique: true }
});

const Post = sequelize.define('Post', {
  title: DataTypes.STRING,
  content: DataTypes.TEXT
});

User.hasMany(Post);
Post.belongsTo(User);

await sequelize.sync();
const user = await User.create({ name: 'Alice', email: 'alice@example.com' });
const posts = await user.getPosts();
§05

Related on TokRepo

§06

Common pitfalls

  • Eager loading without limits can generate massive SQL joins. Always specify include with limit and attributes to avoid loading entire tables into memory.
  • The sync({ force: true }) method drops and recreates tables. Never use it in production; use migrations instead.
  • Sequelize v7 introduced breaking changes from v6. Check the migration guide before upgrading existing projects.

Preguntas frecuentes

Does Sequelize support TypeScript?+

Yes. Sequelize has built-in TypeScript type definitions. Version 7 improved TypeScript support significantly with better generic types for model attributes and associations.

How does Sequelize compare to Prisma?+

Prisma uses a schema-first approach with its own schema language and generates a type-safe client. Sequelize uses a code-first approach with JavaScript/TypeScript model definitions. Prisma offers better type safety; Sequelize offers more mature features and broader database support.

Can Sequelize handle raw SQL queries?+

Yes. Use sequelize.query() for raw SQL when the ORM abstraction does not fit. You can use replacements for parameterized queries and map results to model instances.

Does Sequelize support connection pooling?+

Yes. Sequelize uses connection pooling by default. You can configure pool size, idle timeout, and acquire timeout in the constructor options.

Is Sequelize suitable for large-scale applications?+

Sequelize works well for medium to large applications. For very high-throughput scenarios, monitor generated SQL carefully and use raw queries for performance-critical paths. Connection pool tuning is important at scale.

Referencias (3)

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados