People might have confusion when we start to think about traditional ORM like sequelize.
Got the explanation “Sequelize vs Prisma” from Prisma
While Prisma and Sequelize solve similar problems, they work in very different ways.
Sequelize is a traditional ORM which maps tables to model classes. Instances of the model classes then provide an interface for CRUD queries to an application at runtime.
Prisma is a new kind of ORM that mitigates many problems of traditional ORMs, such as bloated model instances, mixing business with storage logic, lack of type-safety or unpredictable queries caused e.g. by lazy loading.
It uses the Prisma schema to define application models in a declarative way. Prisma Migrate then allows to generate SQL migrations from the Prisma schema and executes them against the database. CRUD queries are provided by Prisma Client, a lightweight and entirely type-safe database client for Node.js and TypeScript.
Battle of the Node.js ORMs: Objection vs. Prisma vs. Sequelize
The first impression of Objection.js is more like a query builder instead of a common ORM. The way of defining models and relationships can be nicely achieved with custom methods, json and schema validation. We can also do Database transactions easily with promise.
const people = await Person.query()
.select('parent:parent.name as grandParentName')
.joinRelated('parent.parent');
console.log(people[0].grandParentName);
select "parent:parent"."firstName" as "grandParentName"
from "persons"
inner join "persons"
as "parent"
on "parent"."id" = "persons"."parentId"
inner join "persons"
as "parent:parent"
on "parent:parent"."id" = "parent"."parentId"
The eager loading is quite interesting too. “withGraphFetched and withGraphJoined. The main difference is that withGraphFetched uses multiple queries under the hood to fetch the result while withGraphJoined uses a single query and joins to fetch the results. Both methods allow you to do different things which we will go through in detail in the examples below and in the examples of the withGraphJoined method.”