Bird
0
0

How can you perform a transaction in NestJS Prisma to update two related records atomically?

hard📝 Application Q9 of 15
NestJS - Database with Prisma
How can you perform a transaction in NestJS Prisma to update two related records atomically?
AWrap updates in a try-catch block only
BUse prisma.$transaction() with an array of update calls
CUse prisma.transaction.update() method
DCall update() twice sequentially without transaction
Step-by-Step Solution
Solution:
  1. Step 1: Understand Prisma transactions

    Prisma provides $transaction() to run multiple queries atomically.
  2. Step 2: Confirm correct usage

    Passing an array of update calls to $transaction() ensures atomicity.
  3. Step 3: Evaluate incorrect options

    Sequential updates without transaction risk partial updates; prisma.transaction.update() does not exist.
  4. Final Answer:

    Use prisma.$transaction() with an array of update calls -> Option B
  5. Quick Check:

    Atomic updates use prisma.$transaction() [OK]
Quick Trick: Use $transaction() to run multiple queries atomically [OK]
Common Mistakes:
  • Updating sequentially without transaction
  • Using non-existent prisma.transaction.update()
  • Relying only on try-catch without transaction

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes