Skip to content

Instantly share code, notes, and snippets.

@ataube
Created August 14, 2016 20:25
Show Gist options
  • Save ataube/580c1a2f14343c24eb2923949e230378 to your computer and use it in GitHub Desktop.
Save ataube/580c1a2f14343c24eb2923949e230378 to your computer and use it in GitHub Desktop.
Loopback async/await transaction example
const Transaction = require('loopback-datasource-juggler');
const update = async (ids, delta) => {
const result = [];
const tx = await models.MyModel.beginTransaction({ isolationLevel: Transaction.READ_COMMITTED });
try {
for (const id of ids) {
const entity = await updateById(id, delta, { transaction: tx });
result.push(entity);
}
await tx.commit();
} catch (e) {
await tx.rollback();
throw e;
}
return result;
};
@dmastag
Copy link

dmastag commented Oct 26, 2018

Thanks! This really helped me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment