पाठ 33 / 35

Cheat Sheet: The Three ORMs Side by Side

यह पाठ अभी हिंदी में अनुवादित नहीं है, इसलिए अंग्रेज़ी में दिखाया जा रहा है।

Revise the equivalent methods, options and commands of Prisma, TypeORM and Sequelize in one place before an exam or interview.

लेखक: · 15 साल से वेब डेवलपर

The whole course on one page

Define: Prisma model in schema.prisma; TypeORM @Entity() classes; Sequelize define or Model.init. Connect: one PrismaClient; new DataSource(...) then initialize(); one new Sequelize(...). Read: findUnique, findFirst, findMany; findOneBy, findOne, find; findByPk, findOne, findAll. Write: create, update, upsert, delete, plus updateMany and deleteMany; save, update, delete, remove; create, update, destroy, bulkCreate. Relations: include or select; relations; include. Filters: nested { gte } and OR; helpers like MoreThan, In and a where array for OR; Op.gte and Op.or. Transactions: $transaction; dataSource.transaction; sequelize.transaction with { transaction: t }. Migrations: migrate dev and migrate deploy; migration:generate and migration:run; sequelize-cli db:migrate with hand-written files. Remember: log the SQL, avoid N+1, parameterise raw SQL, never auto-sync production.

How to revise

Read the cheat sheet, practise explaining the common questions out loud, then test yourself with the mixed quiz.

Three connected stages: review the cheat sheet, practise interview questions, take the self-check quiz.
Figure 11.1: cheat sheet -> practise questions -> self-check quiz

Learn one ORM deeply, the others by mapping

Pick the ORM your projects use and practise it hands-on. For the other two, learn the mapping table above. In interviews, saying 'in Prisma I would use include; the TypeORM equivalent is the relations option' shows transferable understanding.

त्वरित जाँच: Which trio correctly lists the 'find by primary key' style method in Prisma, TypeORM and Sequelize, in that order?

  • findByPk, findOneBy, findUnique
  • findMany, find, findAll
  • findFirst, findOne, findOne
  • findUnique, findOneBy, findByPk
Answer

findUnique, findOneBy, findByPk — Prisma findUnique({ where: { id } }), TypeORM findOneBy({ id }) and Sequelize findByPk(id) all fetch one row by key and return null if it is missing.