Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction support proposal #741

Open
gsi-alejandro opened this issue Oct 24, 2023 · 4 comments
Open

Transaction support proposal #741

gsi-alejandro opened this issue Oct 24, 2023 · 4 comments

Comments

@gsi-alejandro
Copy link
Collaborator

gsi-alejandro commented Oct 24, 2023

Ref: CBSE-14946

Proposal

Steps:

  1. Add $transaction method to the ottoman instance.
  2. Update existing methods to support transactions (the proposal will not include any breaking change)
  3. Add a test suit for the transaction feature.
  4. 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.

@ejscribner
Copy link
Collaborator

Is there a strong motivation to use .$transaction instead of just .transaction?

@gsi-alejandro
Copy link
Collaborator Author

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)

@AV25242
Copy link
Contributor

AV25242 commented Nov 1, 2023

@gsi-alejandro .$transactions will it be made available as an “interactive” transaction?

@AV25242
Copy link
Contributor

AV25242 commented Nov 1, 2023

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants