0

I am using loopback 4. When I execute the commit, in different situations the connection is closed, if i execute the query without transaction it is fine, it inserts the record quietly. it often happens to me when I run a query multiple times within a foreach. Could you please tell me how to solve? I report below an example of a commit

        const repo = new DefaultTransactionalRepository(oggetto, this.classerepository.dataSource);
        const tx = await repo.beginTransaction();
        try {
             this.repository.create(oggetto, {transaction: tx});
             this.other_repository.create(oggetto2, {transaction: tx});
             tx.commit();
         
        } catch (e) {
             tx.rollback();
        } 
  
  • I solved my problem with https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop . I used for … of instead of foreach . Now it run all create and then commit correctly. – Pasquale Pace Oct 22 '22 at 07:35

0 Answers0