Skip to content

Introduce explicity resource management to Transaction #1155

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

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

bigmontz
Copy link
Contributor

This is a TC39 proposal which is already implemented in Typescript 5.2, core-js, babel and other polyfill tools.

This feature enables the user begin a transaction with the await using keywords and then do not have to close the resource afterwards, since this resources will be closed after leaving the block which were created at.

Transaction will be closed using with the same behaviour as Transaction.close calls. So, the transaction will be rollback if still open.

Note: For better usage in cluster environments, you should use executeRead and executeWrite for handling retries.

Usage example:

await using tx = session.beginTransaction()
await tx.run('CREATE (p:Person { name:$name }) RETURN p', { name }).summary()
await tx.commit()

This is a TC39 [proposal](https://github.com/tc39/proposal-explicit-resource-management) which is already implemented in Typescript 5.2, core-js, babel and other polyfill tools.

This feature enables the user begin a transaction with the `await using` keywords and then do not have to close the resource afterwards, since this resources will be closed after leaving the block which were created at.

Transaction will be closed using with the same behaviour as `Transaction.close` calls.
So, the transaction will be rollback if still open.

_Note: For better usage in cluster environments, you should use `executeRead` and `executeWrite` for handling retries._

Usage example:

```typescript
await using tx = session.beginTransaction()
await tx.run('CREATE (p:Person { name:$name }) RETURN p', { name }).summary()
await tx.commit()
```
@bigmontz bigmontz merged commit f58a089 into neo4j:5.0 Oct 30, 2023
@bigmontz bigmontz deleted the 5.15-erm-trasanction branch October 30, 2023 15:36
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