Complete the code to start a transaction using TypeORM's QueryRunner.
const queryRunner = dataSource.createQueryRunner();
await queryRunner.connect();
await queryRunner.[1]();To begin a transaction, you use startTransaction() on the QueryRunner.
Complete the code to commit the transaction after successful operations.
try { // some database operations await queryRunner.[1](); } catch (error) { await queryRunner.rollbackTransaction(); }
After successful operations, you commit the transaction using commitTransaction().
Fix the error in the transaction cleanup by completing the code to release the QueryRunner.
finally {
await queryRunner.[1]();
}After finishing the transaction, always release the QueryRunner with release() to free resources.
Fill both blanks to create a transaction that rolls back on error and releases the QueryRunner.
try { await queryRunner.startTransaction(); // operations await queryRunner.commitTransaction(); } catch (error) { await queryRunner.[1](); } finally { await queryRunner.[2](); }
On error, rollback the transaction with rollbackTransaction(), then always release the QueryRunner with release().
Fill all three blanks to create an object that maps entity names to their repository instances inside a transaction.
const repositories = {
[1]: queryRunner.manager.getRepository([2]),
[3]: queryRunner.manager.getRepository(ProductEntity),
};Keys are strings like "userEntity" and "productEntity", values are entity classes like UserEntity and ProductEntity.