Prisma / TypeORM / Sequelize Interview Questions Hindi mein

Prisma / TypeORM / Sequelize कोर्स के 35 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

Prerequisites and the ORM Mental Model

1. Which statement about ORMs is correct?

  1. An ORM stores data in its own format, so the database never sees SQL
  2. An ORM generates SQL from method calls and converts the result rows back into objects
  3. An ORM only works with NoSQL databases
  4. An ORM makes indexes unnecessary because it caches every table in memory
जवाब देखें

जवाब: An ORM generates SQL from method calls and converts the result rows back into objects

The ORM is a translation layer. The database still receives and executes ordinary SQL, so indexes, joins and query plans still matter.

पाठ: What an ORM Actually Does

2. In a relational database, how does a post usually record which user wrote it?

  1. By storing a copy of the whole user object inside the post row
  2. By storing a memory reference to the user
  3. By storing an array of post IDs inside the user row
  4. By storing the user's primary key in a foreign key column such as author_id
जवाब देखें

जवाब: By storing the user's primary key in a foreign key column such as author_id

Relational tables link rows through foreign keys. The ORM turns that key into an object reference when you ask it to load the relation.

पाठ: The Object-Relational Mismatch

3. A LEFT JOIN from users to posts returns what for a user who has no posts?

  1. One row for that user with NULL in the post columns
  2. No row for that user
  3. An error, because the foreign key is missing
  4. One row per post in the whole table
जवाब देखें

जवाब: One row for that user with NULL in the post columns

A left join keeps every row from the left table. Where no matching post exists, the post columns are NULL. An inner join would drop the user instead.

पाठ: The SQL You Need Before Any ORM

Foundations: Meet and Set Up the Three ORMs

4. Which ORM generates a typed client from a separate schema file?

  1. TypeORM
  2. Sequelize
  3. Prisma
  4. All three generate a client from a schema file
जवाब देखें

जवाब: Prisma

Prisma reads schema.prisma and generates Prisma Client. TypeORM reads decorators on classes, and Sequelize reads model definitions written in JavaScript.

पाठ: Three ORMs, Three Design Styles

5. You added a phone field to the User model. What must happen before prisma.user.create can accept phone with correct types?

  1. Nothing; Prisma reads the schema at runtime on every query
  2. The client must be regenerated with prisma generate
  3. You must add a @Column decorator to the User class
  4. You must call sequelize.sync()
जवाब देखें

जवाब: The client must be regenerated with prisma generate

Prisma Client is generated code. Schema changes reach your types only after regeneration; the database table changes only after a migration is applied.

पाठ: Setting Up Prisma

6. Why should synchronize: true be avoided in a production TypeORM DataSource?

  1. It disables query logging
  2. It makes every query run inside a transaction
  3. It only works with SQLite
  4. It changes the schema automatically on startup and can drop columns or data
जवाब देखें

जवाब: It changes the schema automatically on startup and can drop columns or data

synchronize compares entities with the database and applies changes directly. A rename can look like drop-and-add, losing data. Migrations give you a reviewed, repeatable change instead.

पाठ: Setting Up TypeORM

7. With default options, which table does sequelize.define('Order', ...) map to?

  1. order
  2. Orders
  3. tbl_order
  4. Order, exactly as written
जवाब देखें

जवाब: Orders

Sequelize pluralises the model name by default. Set tableName or freezeTableName: true when you need a different table name.

पाठ: Setting Up Sequelize

Modelling Data: Fields and Relations

8. In Sequelize, what happens if you omit allowNull on an attribute?

  1. The column allows NULL, because allowNull defaults to true
  2. The column is NOT NULL
  3. Sequelize throws an error at define time
  4. The column becomes the primary key
जवाब देखें

जवाब: The column allows NULL, because allowNull defaults to true

Sequelize's allowNull defaults to true. Prisma fields and TypeORM columns are required by default, so mixing the three can lead to accidental nullable columns.

पाठ: Fields, Types, Nullability and Defaults

9. For a relation 'a course has many lectures', which table should hold the foreign key?

  1. courses, as an array of lecture IDs
  2. A third join table is always required
  3. Both tables, pointing at each other
  4. lectures, as a courseId column
जवाब देखें

जवाब: lectures, as a courseId column

In one-to-many, the many side (lectures) stores the key of the one side (course). Join tables are only needed for many-to-many.

पाठ: One-to-Many and One-to-One Relations

10. Students enrol in courses and you must store each student's grade per course. What is the best model?

  1. A grades array column on the Student table
  2. An implicit many-to-many between Student and Course
  3. An explicit Enrollment model with studentId, courseId and grade
  4. A courseId column on Student
जवाब देखें

जवाब: An explicit Enrollment model with studentId, courseId and grade

The grade belongs to the pair (student, course), so it must live on the join table. That means making the join table an explicit model.

पाठ: Many-to-Many Relations and Join Tables

Core Mechanics: CRUD Queries

11. prisma.user.findUnique({ where: { id: 999 } }) is called and no such user exists. What happens?

  1. It throws a not-found error
  2. It returns an empty array
  3. It returns null
  4. It creates the user
जवाब देखें

जवाब: It returns null

findUnique returns null when nothing matches. Use findUniqueOrThrow if you want an error instead. List methods return an empty array.

पाठ: Creating and Reading Records

12. Two requests read views = 10 at the same time, both add 1 in JavaScript and save. What is the stored value afterwards?

  1. 11, because one update overwrites the other
  2. 12, because databases serialise all writes
  3. An error, because the ORM detects the conflict
  4. 10, because neither save succeeds
जवाब देखें

जवाब: 11, because one update overwrites the other

This is a lost update. Both write 11. An atomic increment (SET views = views + 1) or optimistic locking prevents it.

पाठ: Updating, Deleting and Upserting

13. In TypeORM's find(), how do you express 'city is Pune OR city is Indore'?

  1. where: { city: 'Pune', city: 'Indore' }
  2. where: { OR: ['Pune', 'Indore'] }
  3. where: { city: { [Op.or]: ['Pune', 'Indore'] } }
  4. where: [{ city: 'Pune' }, { city: 'Indore' }] or where: { city: In(['Pune', 'Indore']) }
जवाब देखें

जवाब: where: [{ city: 'Pune' }, { city: 'Indore' }] or where: { city: In(['Pune', 'Indore']) }

TypeORM treats an array of where objects as OR, and In() generates an IN list. Op.or is Sequelize syntax, and OR is Prisma syntax.

पाठ: Filtering, Sorting and Pagination

14. In TypeORM, you save a new User whose posts array contains two new Post entities, but no posts are inserted. What is the most likely cause?

  1. TypeORM never saves related entities
  2. The relation does not have cascade enabled
  3. Posts must be saved before users in every case
  4. The DataSource has logging enabled
जवाब देखें

जवाब: The relation does not have cascade enabled

Without cascade on the OneToMany relation, TypeORM does not insert related entities when saving the parent. Enable cascade for inserts or save the posts separately.

पाठ: Nested Writes: Creating Related Records Together

Core Mechanics: Loading Relations and Going Beyond CRUD

15. Why can a Prisma query not use both include and select at the same level?

  1. select already lets you choose relations and fields, so include at the same level would conflict
  2. include only works with MySQL
  3. select is deprecated
  4. include and select both run raw SQL
जवाब देखें

जवाब: select already lets you choose relations and fields, so include at the same level would conflict

include means 'all scalar fields plus these relations'; select means 'exactly these fields and relations'. You can nest one inside the other, but not combine them at the same level.

पाठ: Including Relations and Selecting Fields

16. Which change fixes an N+1 problem when listing 200 orders with their customers in Prisma?

  1. Adding an index on the orders table's primary key
  2. Increasing the connection pool size
  3. Using include: { customer: true } in the findMany call instead of fetching each customer inside a loop
  4. Wrapping the loop in a transaction
जवाब देखें

जवाब: Using include: { customer: true } in the findMany call instead of fetching each customer inside a loop

The cost comes from the number of round trips. Loading customers with include (or one IN query) collapses 201 queries into one or two. More connections or a transaction do not reduce the count.

पाठ: The N+1 Query Problem

17. Which call is vulnerable to SQL injection if name comes from a request?

  1. prisma.$queryRaw`SELECT * FROM users WHERE name = ${name}`
  2. repo.createQueryBuilder('u').where('u.name = :name', { name })
  3. sequelize.query('SELECT * FROM users WHERE name = :name', { replacements: { name } })
  4. prisma.$queryRawUnsafe(`SELECT * FROM users WHERE name = '${name}'`)
जवाब देखें

जवाब: prisma.$queryRawUnsafe(`SELECT * FROM users WHERE name = '${name}'`)

The Unsafe variant receives a fully built string, so the quote in a crafted name ends the literal. The other three send name as a bound or escaped parameter.

पाठ: Query Builders, Aggregates and Raw SQL

Evolving the Schema with Migrations

18. How does an ORM know which migrations still need to run on a database?

  1. It compares file modification dates with the server clock
  2. It reruns every migration each time and ignores errors
  3. It reads a bookkeeping table in that database that lists applied migrations
  4. It asks the developer interactively in production
जवाब देखें

जवाब: It reads a bookkeeping table in that database that lists applied migrations

Each ORM stores applied migration names in a table such as _prisma_migrations, migrations or SequelizeMeta, and applies only those not yet recorded.

पाठ: Why Migrations Beat Auto-Sync

19. Which Prisma command belongs in a production deployment pipeline?

  1. prisma migrate dev
  2. prisma migrate deploy
  3. prisma migrate reset
  4. prisma db push --force-reset
जवाब देखें

जवाब: prisma migrate deploy

migrate deploy applies already-committed migrations and nothing else. The other commands can create migrations, reset data or bypass migration history.

पाठ: Prisma Migrate in Practice

20. What does typeorm migration:revert do?

  1. Rolls back every migration ever applied
  2. Deletes the migration files from disk
  3. Regenerates the latest migration from entities
  4. Runs the down method of the most recently applied migration
जवाब देखें

जवाब: Runs the down method of the most recently applied migration

revert undoes one migration at a time, the last one recorded in the migrations table, by calling its down method.

पाठ: TypeORM Migrations

21. You added a phone attribute to a Sequelize model and ran db:migrate, but INSERTs fail with 'column phone does not exist'. Why?

  1. sequelize-cli does not generate migrations from model changes, so no migration added the column
  2. db:migrate only runs in production
  3. Sequelize requires a restart of the database server
  4. The phone attribute must be declared in SequelizeMeta
जवाब देखें

जवाब: sequelize-cli does not generate migrations from model changes, so no migration added the column

Sequelize CLI migrations are written by hand. Without a migration calling addColumn, the table never gained the column even though the model mentions it.

पाठ: Sequelize CLI Migrations

Transactions, Integrity and Concurrency

22. Which ACID property guarantees that a half-finished transfer is undone when the second update fails?

  1. Durability
  2. Isolation
  3. Consistency
  4. Atomicity
जवाब देखें

जवाब: Atomicity

Atomicity is the all-or-nothing property. Consistency is about constraints holding, isolation about concurrent visibility, durability about surviving crashes after commit.

पाठ: Transactions and ACID

23. Inside a Sequelize managed transaction, a query is written without { transaction: t } and CLS is not configured. What happens to it if the transaction later rolls back?

  1. It is rolled back too, because it ran inside the callback
  2. It ran on a separate connection outside the transaction, so its change is not rolled back
  3. Sequelize refuses to run it and throws
  4. It is retried automatically after the rollback
जवाब देखें

जवाब: It ran on a separate connection outside the transaction, so its change is not rolled back

Being inside the callback is not enough. Without the transaction option (or CLS), Sequelize runs the query outside the transaction, so it commits independently.

पाठ: Transaction APIs in Prisma, TypeORM and Sequelize

24. A ticket-booking app expects heavy contention on the last few seats of a popular show. Which approach is usually more suitable for those seat rows?

  1. No locking, relying on default isolation alone
  2. Optimistic locking, since conflicts are expected to be rare
  3. Pessimistic locking with SELECT ... FOR UPDATE inside a short transaction
  4. Disabling transactions to improve speed
जवाब देखें

जवाब: Pessimistic locking with SELECT ... FOR UPDATE inside a short transaction

When conflicts are frequent, optimistic locking produces many failed retries. Locking the row briefly makes contenders wait in turn, which is clearer for hot rows.

पाठ: Concurrency: Optimistic and Pessimistic Locking

Real-World Usage and Tooling

25. An Express app creates new PrismaClient() inside every request handler. What problem is most likely under load?

  1. Queries return stale data from a cache
  2. Too many connection pools are opened and the database runs out of connections
  3. Migrations run on every request
  4. TypeScript types are lost
जवाब देखें

जवाब: Too many connection pools are opened and the database runs out of connections

Each client owns its own pool. Creating one per request multiplies connections until the database limit is hit. Create one client per process and reuse it.

पाठ: Client Lifecycle, Connection Pools and Project Layout

26. Why are integration tests against a real test database preferred over mocking the ORM for query logic?

  1. Mocks are not allowed in Node.js test runners
  2. Real databases are always faster than mocks
  3. A mock cannot catch wrong filters, joins or constraint violations that only the database evaluates
  4. ORMs cannot be imported in test files
जवाब देखें

जवाब: A mock cannot catch wrong filters, joins or constraint violations that only the database evaluates

The bug is usually in what the SQL does. Only executing it against a real database proves the filter, join or constraint behaves as intended.

पाठ: Seeding and Testing with a Real Database

27. In TypeORM, user.posts is typed Post[], but you called findOneBy({ id }) without relations. What is user.posts at runtime?

  1. An empty array
  2. A Promise that loads the posts
  3. All posts in the table
  4. undefined, because the relation was not loaded
जवाब देखें

जवाब: undefined, because the relation was not loaded

The entity type describes the shape when loaded, not what was actually fetched. Without relations (or eager: true), the property is simply not set.

पाठ: Type Safety and Input Validation

Performance, Security and Pitfalls

28. An infinite-scroll feed with millions of rows gets slower the further a user scrolls. It uses skip/take with large offsets. What is the best fix?

  1. Switch to cursor pagination on an indexed, ordered key
  2. Increase take so fewer pages are requested
  3. Remove ORDER BY to save sorting time
  4. Wrap each page query in a transaction
जवाब देखें

जवाब: Switch to cursor pagination on an indexed, ordered key

Large offsets force the database to skip rows one by one. Keyset or cursor pagination seeks directly via the index, so every page costs about the same.

पाठ: Making ORM Queries Fast

29. A sort parameter from the URL is used as the column name in ORDER BY. What is the correct protection?

  1. Bind it as a query parameter like any value
  2. Map the input to a fixed whitelist of allowed column names
  3. Escape single quotes in the input
  4. Convert the input to upper case
जवाब देखें

जवाब: Map the input to a fixed whitelist of allowed column names

Parameters bind values, not identifiers. A whitelist guarantees only known column names ever reach the SQL.

पाठ: Security: Injection, Mass Assignment and Secrets

30. A Sequelize model uses paranoid: true. A user is 'deleted' with destroy(). What happens to the row?

  1. It is permanently removed from the table
  2. It is moved to an archive table automatically
  3. The whole table is truncated
  4. It stays in the table with deletedAt set, and normal finders exclude it
जवाब देखें

जवाब: It stays in the table with deletedAt set, and normal finders exclude it

Paranoid models perform soft deletes by setting deletedAt. Finders skip such rows unless you pass paranoid: false, and destroy({ force: true }) removes them for real.

पाठ: Common Pitfalls and How to Avoid Them

Choosing an ORM and Knowing When Not To

31. 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?

  1. Rewrite every model in Prisma first
  2. Add TypeORM alongside for the new feature only
  3. Keep using Sequelize for the feature and add migrations and tests around it
  4. Remove the ORM and use only raw SQL from now on
जवाब देखें

जवाब: 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.

पाठ: Prisma vs TypeORM vs Sequelize

32. Which statement best describes a query builder such as Knex or Kysely compared with a full ORM?

  1. It composes SQL with functions but does not manage models, relation loading or object identity like an ORM does
  2. It is a database server
  3. It replaces the need for a database driver
  4. It always generates faster SQL than an ORM
जवाब देखें

जवाब: It composes SQL with functions but does not manage models, relation loading or object identity like an ORM does

Query builders sit between raw SQL and ORMs: they help write SQL safely and dynamically, but stop short of model and relation management.

पाठ: Query Builders, Raw SQL and Hybrid Approaches

Revision and Interview Prep

33. Which trio correctly lists the 'find by primary key' style method in Prisma, TypeORM and Sequelize, in that order?

  1. findByPk, findOneBy, findUnique
  2. findMany, find, findAll
  3. findFirst, findOne, findOne
  4. findUnique, findOneBy, findByPk
जवाब देखें

जवाब: 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.

पाठ: Cheat Sheet: The Three ORMs Side by Side

34. In the Active Record pattern, which statement is true?

  1. Entities are plain objects and a separate repository saves them
  2. Model instances carry their own persistence methods such as save() and destroy()
  3. There is no database involved
  4. Only raw SQL may be used
जवाब देखें

जवाब: Model instances carry their own persistence methods such as save() and destroy()

Active Record puts persistence on the model instance itself, as in Sequelize or TypeORM entities extending BaseEntity. Data Mapper keeps persistence in repositories.

पाठ: Common Interview and Exam Questions

35. In the snippet above, an exception is thrown after two of five stock updates. Which statement is correct?

  1. Everything is rolled back, including the two stock updates
  2. Nothing is rolled back, including the order
  3. The order insert is rolled back, but the two stock updates stay committed because they used prisma instead of tx
  4. Prisma retries the remaining three updates automatically
जवाब देखें

जवाब: The order insert is rolled back, but the two stock updates stay committed because they used prisma instead of tx

Only queries made through tx belong to the transaction. The order (created with tx) is rolled back; the stock updates through the global client already committed.

पाठ: Mixed Self-Check

← कोर्स पर वापस जाएँ