NestJS - Database with TypeORMIn a NestJS service using TypeORM, how do you correctly initiate a transaction with the DataSource instance?Aawait dataSource.transaction(async (manager) => { /* transactional code */ });Bawait dataSource.startTransaction();Cawait dataSource.begin();Dawait dataSource.createTransaction();Check Answer
Step-by-Step SolutionSolution:Step 1: Use DataSource.transaction()The TypeORM DataSource provides a transaction method that accepts a callback with a transactional EntityManager.Step 2: Pass an async callbackThe callback receives a manager to perform operations atomically.Final Answer:await dataSource.transaction(async (manager) => { /* transactional code */ }); -> Option AQuick Check:Check method name and usage [OK]Quick Trick: Use dataSource.transaction() with async callback [OK]Common Mistakes:Using non-existent methods like startTransaction()Calling transaction without async callbackTrying to manually manage transactions without DataSource
Master "Database with TypeORM" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Authentication - Protected routes with guards - Quiz 14medium Database with Prisma - Why Prisma offers type-safe database access - Quiz 4medium Database with Prisma - CRUD with Prisma - Quiz 12easy Database with TypeORM - Migrations - Quiz 2easy Database with TypeORM - Relations (OneToMany, ManyToOne, ManyToMany) - Quiz 2easy Guards - Guard binding levels - Quiz 11easy Interceptors - Interceptor interface - Quiz 13medium Interceptors - Response transformation - Quiz 11easy Interceptors - Timeout interceptor - Quiz 1easy Middleware - Third-party middleware (cors, helmet) - Quiz 1easy