Skip to content

Return a promise from transaction as per README and transaction error handling improvements#113

Merged
ospfranco merged 3 commits intoospfranco:mainfrom
pbbadenhorst:feat/transaction-returns-promise
Jan 20, 2023
Merged

Return a promise from transaction as per README and transaction error handling improvements#113
ospfranco merged 3 commits intoospfranco:mainfrom
pbbadenhorst:feat/transaction-returns-promise

Conversation

@pbbadenhorst
Copy link
Copy Markdown
Contributor

Notice that the changes in README for previous PR expected transaction to return a Promise. This PR implements that.

This PR contains.

  • added Promise returned from transaction.
  • improved error handling and removing of some unhandled promise rejection messages (see note on PendingTransaction start() method).
  • applied prettier formatting to the code changed.

Comment thread src/index.ts
executeAsync: (
query: string,
params?: any[] | undefined
) => Promise<QueryResult>;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to match actual return

Comment thread src/index.ts
fn: (tx: TransactionAsync) => Promise<any>
) => Promise<void>;
transaction: (dbName: string, fn: (tx: Transaction) => void) => void;
transaction: (dbName: string, fn: (tx: Transaction) => void) => Promise<void>;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change - to match the README documentation

Comment thread src/index.ts
return new Promise((resolve, reject) => {
const tx: PendingTransaction = {
start: () => {
run().then(resolve).catch(reject);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored the body out

@ospfranco
Copy link
Copy Markdown
Owner

To be honest, now that the transactions are returning promises, there is no need for transactionAync... I think I will scratch that entire section and just have one "transaction" method.

I will just merge your PR and work on the refactor.

@ospfranco ospfranco merged commit e5fe206 into ospfranco:main Jan 20, 2023
@pbbadenhorst pbbadenhorst deleted the feat/transaction-returns-promise branch January 23, 2023 17:37
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

Successfully merging this pull request may close these issues.

2 participants