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 system #12

Closed
7 tasks done
stombre opened this issue Sep 4, 2020 · 1 comment
Closed
7 tasks done

Transaction system #12

stombre opened this issue Sep 4, 2020 · 1 comment
Labels
component - transaction Subject related to Transaction enhancement New feature or request

Comments

@stombre
Copy link
Contributor

stombre commented Sep 4, 2020

Support a transaction system make sense;

  • Define API
  • Transaction class
  • Transaction on query
  • Transaction on model
  • Test all cases
  • Documentation
  • Uncaught exception / local storage

API proposal (with async local storage);

const { Transaction } = ilorm;

Transaction.run(async () => {
  // everything here is in the transaction
  const account = await account.query().findOne({ ... });

  if (account.balance > amountMoney) {
    item.isBuyed = true;
    account.balance -= amountMoney;
    await Promise.all([
      item.save(),
      account.save(),
    ]);
  }
});

More declarative one;

Transaction.run(async (trx) => {
  // everything here is in the transaction
  const account = await account.query(trx).findOne({ ... });

  if (account.balance > amountMoney) {
    item.isBuyed = true;
    account.balance -= amountMoney;
    await Promise.all([
      item.save(trx),
      account.save(trx),
    ]);
  }
});

Exception cancel transaction? 🤔

Quid multi connector / ilorm?

Alternative syntax;

const trx = new Transaction();
const account = await account.query(trx).findOne({ ... });

if (account.balance > amountMoney) {
  item.isBuyed = true;
  account.balance -= amountMoney;
  await Promise.all([
    item.save(trx),
    account.save(trx),
  ]);
}

await trx.commit();
@stombre stombre added the enhancement New feature or request label Sep 4, 2020
@stombre stombre added the component - transaction Subject related to Transaction label Sep 15, 2020
@stombre
Copy link
Contributor Author

stombre commented Sep 15, 2020

Part of the subject are tracked here; #17 #16
PR related to transaction merged #15

@stombre stombre closed this as completed Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component - transaction Subject related to Transaction enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant