# Prisma vs TypeORM vs Sequelize — Prisma / TypeORM / Sequelize

Source: https://www.skillbyai.com/en/orms/or-comparison

> Compare the three ORMs on modelling style, type safety, migrations, query flexibility and ecosystem, and match each to a project.

## Trade-offs, not winners

Compare ORMs on the dimensions that affect your daily work. **Modelling**: Prisma has a single schema file that is easy to read and review; TypeORM keeps the model in TypeScript classes next to your code; Sequelize defines models in JavaScript objects. **Type safety**: Prisma's generated, query-shaped types are the strongest of the three; TypeORM's entity types are good but can claim relations exist when they were not loaded; Sequelize needs the most manual typing. **Migrations**: Prisma and TypeORM generate migrations from model changes; Sequelize CLI migrations are written by hand. **Query flexibility**: TypeORM's QueryBuilder covers complex joins and subqueries without raw SQL; Prisma leans on raw SQL for queries its API cannot express; Sequelize sits between. **Patterns**: TypeORM supports both Data Mapper (repositories) and Active Record (entities extending `BaseEntity`); Sequelize is Active Record; Prisma is neither, offering a query client over plain objects. Also weigh team familiarity and the framework you use; NestJS, for example, has official integrations for TypeORM and Sequelize and documents Prisma usage.

## A decision process

List your requirements, compare the trade-offs against them, prototype the hardest query in your top choice, then decide and document why.

![Four connected stages: gather requirements, compare trade-offs, prototype the hardest query, make and record the decision.](assets/figures/orms/section-10-map.svg) — Figure 10.1: requirements -> compare trade-offs -> prototype -> decide

## Choosing a two-wheeler

A scooter, a commuter bike and a sports bike all get you to college. Which one is right depends on the road, the distance and who else will ride it. Picking an ORM is the same: the best choice for a solo TypeScript project differs from one for an old JavaScript codebase maintained by a large team.

## Prototype the hardest query first

Before committing, write the most complex report or search your app needs in the candidate ORM. If it already needs raw SQL or ten lines of workarounds, you have learned more than any feature table could tell you.

**Quiz:** A team maintains a large plain-JavaScript Express codebase that already uses Sequelize models with hooks. They want to add one new feature. What is the most reasonable choice?

- [ ] Rewrite every model in Prisma first
- [ ] Add TypeORM alongside for the new feature only
- [x] Keep using Sequelize for the feature and add migrations and tests around it
- [ ] Remove the ORM and use only raw SQL from now on

*Answer:* Keep using Sequelize for the feature and add migrations and tests around it. Switching ORMs is costly and risky. For incremental work in an existing codebase, consistency usually beats a theoretical improvement.
