neo4j / neo4j-javascript-driver

Neo4j Bolt driver for JavaScript
https://neo4j.com/docs/javascript-manual/current/
Apache License 2.0
859 stars 147 forks source link

Introduce explicity resource management to Transaction #1155

Closed bigmontz closed 1 year ago

bigmontz commented 1 year ago

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()