Bird
0
0

Which of the following is the correct way to start a transaction using TypeORM's DataSource in NestJS?

easy📝 Syntax Q12 of 15
NestJS - Database with TypeORM
Which of the following is the correct way to start a transaction using TypeORM's DataSource in NestJS?
AdataSource.transaction(async (manager) => { /* operations */ })
BdataSource.startTransaction(() => { /* operations */ })
CdataSource.begin(async () => { /* operations */ })
DdataSource.runTransaction(() => { /* operations */ })
Step-by-Step Solution
Solution:
  1. Step 1: Recall TypeORM transaction method

    TypeORM uses dataSource.transaction with an async callback to run transactional code.
  2. Step 2: Check method names

    Only dataSource.transaction(async (manager) => { /* operations */ }) uses the correct method name and async callback pattern.
  3. Final Answer:

    dataSource.transaction(async (manager) => { /* operations */ }) -> Option A
  4. Quick Check:

    Correct method is transaction with async callback [OK]
Quick Trick: Use dataSource.transaction with async callback [OK]
Common Mistakes:
  • Using non-existent methods like startTransaction
  • Omitting async keyword in callback
  • Using wrong method names like begin or runTransaction

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes