NestJS · Middle · Question 32 of 75
How do you run several TypeORM operations in one transaction in Nest?
- ✓Correct answer: Use
dataSource.transaction(async (manager) => ...)and do all operations through thatmanager - 2Start a transaction in the controller with a decorator
- 3Call the repositories as usual; TypeORM wraps them automatically
Explanation
Operations through injected repositories outside the manager don't join the transaction. Libraries like typeorm-transactional use ALS to propagate it.