-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce explicity resource management to Driver and Session objects (…
…#1154) 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 create the driver or a session 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. For example: ```typescript await using driver = neo4j.driver(uri, authToken) await using session = driver.session() await session.executeRead(tx => "RETURN 1") ``` Since Deno is more strict with typescript, small fixes had to be done in the driver. * Add a value to Result[Symbol.toStringTag]. * Fix Integer.shiftRight function to add proper integer conversion it. A package.json file was added to the `neo4j-driver-deno` folder for making easier to integrate the test runners to the environments.
- Loading branch information
Showing
15 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "neo4j-driver-deno", | ||
"version": "5.0.0-dev", | ||
"description": "Package just used for running scripts", | ||
"private": true, | ||
"main": "index.js", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "npm run test::integration", | ||
"test::integration": "deno test --allow-all ./test", | ||
"set_version": "deno run --allow-read --allow-write ./versioning.ts --output=. --filename=current.version.ts", | ||
"build": "deno run --allow-read --allow-write --allow-net ./generate.ts" | ||
}, | ||
"author": "Neo4j", | ||
"license": "Apache-2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import neo4j from '../lib/mod.ts' | ||
|
||
const env = Deno.env.toObject() | ||
|
||
const username = env.TEST_NEO4J_USER || 'neo4j' | ||
const password = env.TEST_NEO4J_PASS || 'password' | ||
const hostname = env.TEST_NEO4J_HOST || 'localhost' | ||
const scheme = env.TEST_NEO4J_SCHEME || 'bolt' | ||
const boltPort = env.TEST_NEO4J_BOLT_PORT || 7687 | ||
const uri = `${scheme}://${hostname}:${boltPort}` | ||
const authToken = neo4j.auth.basic(username, password) | ||
|
||
// Deno will fail with resource leaks | ||
Deno.test('neo4j.driver should be able to use explicity resource management', async () => { | ||
await using driver = neo4j.driver(uri, authToken) | ||
|
||
await driver.executeQuery('RETURN 1') | ||
}) | ||
|
||
// Deno will fail with resource leaks | ||
Deno.test('driver.session should be able to use explicity resource management', async () => { | ||
await using driver = neo4j.driver(uri, authToken) | ||
await using session = driver.session() | ||
|
||
await session.executeRead(tx => "RETURN 1") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters