Trung BìnhDatabase iconDatabase

Sequelize là gì? So sánh với Prisma?

Sequelize là ORM legacy cho Node.js — DX và type safety kém hơn Prisma; chỉ dùng khi maintain legacy codebase hoặc cần polymorphic associations mà Prisma chưa hỗ trợ.

  • Sequelize là ORM lâu đời cho Node.js, hỗ trợ MySQL, PostgreSQL, SQLite, MSSQL, MariaDB.
  • Migration system: sequelize-cli tạo migration files với up/down functions — mạnh nhưng verbose.
  • Hooks (lifecycle events): beforeCreate, afterCreate, beforeUpdate, beforeDestroy — dùng cho audit logging, password hashing.
  • Scopes: defaultScope (applied to all queries), named scopes như User.scope('active') — tái sử dụng query conditions.
  • Transaction support: sequelize.transaction(async (t) => { await Model.create({...}, { transaction: t }) }).
  • Tại sao teams migrate away: TypeScript types không accurate (cần sequelize-typescript), verbose model definitions với decorators, runtime errors khó debug, DX kém so với Prisma.
  • Nên dùng Sequelize khi maintain legacy codebase hoặc cần tính năng như polymorphic associations mà Prisma chưa hỗ trợ.

Xem toàn bộ Database cùng filter theo level & chủ đề con.

Mở danh sách Database