Closed dhmlau closed 5 years ago
loopback4-spring arising from Issue #1599 is a good example of using decorator style to perform transaction.
Can anybody please give an example of how to use transaction with execute() method. I tried below but not getting expected output.
const transaction = await this.employeeRepository.dataSource.beginTransaction(
{isolationLevel: IsolationLevel.READ_COMMITTED}
);
try {
await this.employeeRepository.execute(
`CREATE USER 'TestUser'@'%' IDENTIFIED BY 'TestP@ssword'`,
'', {transaction});
// ... more comands.
await transaction.commit();
} catch {
await transaction.rollback();
}
I'm expecting rollback once catch is called. But not able to rollback it.
Description / Steps to reproduce / Feature proposal
Cross posting my comments:
There are different workarounds that our users have posted:
Loopback 3 provides transaction support at
model
level.In LoopBack 4 this should be at the
Repository
level.There will be
sugar API
in arepository
to delegate the work to thedatasource
level.The
Transaction
type mentioned above should be a wrapper for the typescript type of the transaction object in Juggler.When using the juggler bridge, we need to make sure that the options we set in the wrapper type are consistent with what juggler is expecting.
Since LoopBack 4 doesn't support a distributed transaction, all repos using the transaction must be from the same data source. It is the job of
wrapper
Transaction
to throw an exception if user attempts to use a transaction against disparate data sources.DefaultCRUDRepository will implement an additional interface to handle transactions.
Acceptance criteria
transaction support
in LoopBack 4