Transaction support proposal
gsi-alejandro opened this issue · comments
Ref: CBSE-14946
Proposal
Steps:
- Add $transaction method to the ottoman instance.
- Update existing methods to support transactions (the proposal will not include any breaking change)
- Add a test suit for the transaction feature.
- Update the documentation website with the new transaction content.
ottoman.$transaction((ctx) => {
try {
Model.create(doc, { transactionContext: ctx });
Model.removeById(documentId, { transactionContext: ctx });
Model.findById(documentId, { transactionContext: ctx });
} catch (error) {
if (error instanceof TransactionFailedError) {
console.error('Transaction did not reach commit point', error)
}
if (error instanceof TransactionCommitAmbiguousError) {
console.error('Transaction possibly committed', error)
}
}
});
Note: the way to support transactions will be by passing the ctx via options to the existing method.
Affected methods:
Ottoman:
- query
Model:
- count
- find
- findById
- findOne
- create
- createMany
- updateById
- replaceById
- updateMany
- removeById
- removeMany
- findOneAndUpdate
- query
Document:
- remove
- save
Notice: Bring support to refdoc indexes will be a little bit more complex, no API change is required it will be done under the hood, but you need to be aware of the work to do in order to achieve transactions if refdoc logic is triggered.
Is there a strong motivation to use .$transaction
instead of just .transaction
?
No, .$transaction is inspired by Prismajs's API, it's a clear way to highlight the section like an atomic operation (a different kind of section, a special one)
@gsi-alejandro .$transactions will it be made available as an “interactive” transaction?
Is there a strong motivation to use
.$transaction
instead of just.transaction
?
Yea I think we should us $.transaction @ejscribner . Also are we planning to make Ottoman available from edge environments ?