|
1 |
| -# Neo4j Driver for Deno (Experimental) |
| 1 | +# Neo4j Lite Driver for Deno (Preview) |
2 | 2 |
|
3 |
| -This folder contains a script which can auto-generate a version of |
4 |
| -`neo4j-driver-lite` that is fully compatible with Deno, including complete type |
5 |
| -information. |
| 3 | +> :warning: **This package stills a PREVIEW version.** |
6 | 4 |
|
7 |
| -The resulting driver does not use any dependencies outside of the Deno standard |
8 |
| -library. |
| 5 | +This is the Deno version of the official Neo4j driver for JavaScript. |
9 | 6 |
|
10 |
| -## Development instructions |
| 7 | +This version of driver is based in the `neo4j-driver-lite`. |
| 8 | +So, this version has the same capabilities as the Neo4j Driver except for the support of reactive sessions. |
| 9 | +This means it doesn't have the `RxJS` dependency and the `Driver#rxSession` api. |
11 | 10 |
|
12 |
| -To generate the driver, open a shell in this folder and run this command, |
13 |
| -specifying what version number you want the driver to identify as: |
| 11 | +Starting with 5.0, the Neo4j Drivers will be moving to a monthly release cadence. A minor version will be released on the last Friday of each month so as to maintain versioning consistency with the core product (Neo4j DBMS) which has also moved to a monthly cadence. |
14 | 12 |
|
15 |
| -``` |
16 |
| -deno run --allow-read --allow-write --allow-net ./generate.ts --version=4.4.0 |
| 13 | +As a policy, patch versions will not be released except on rare occasions. Bug fixes and updates will go into the latest minor version and users should upgrade to that. Driver upgrades within a major version will never contain breaking API changes. |
| 14 | + |
| 15 | +See also: https://neo4j.com/developer/kb/neo4j-supported-versions/ |
| 16 | + |
| 17 | +Resources to get you started: |
| 18 | + |
| 19 | +- [API Documentation](https://neo4j.com/docs/api/javascript-driver/current/) |
| 20 | +- [Neo4j Manual](https://neo4j.com/docs/) |
| 21 | +- [Neo4j Refcard](https://neo4j.com/docs/cypher-refcard/current/) |
| 22 | +- [TLS](#tls) |
| 23 | + |
| 24 | +## What's New in 5.x |
| 25 | + |
| 26 | +- [Changelog](https://github.com/neo4j/neo4j-javascript-driver/wiki/5.0-changelog) |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +Importing the driver: |
| 31 | + |
| 32 | +```typescript |
| 33 | +import neo4j from "https://deno.land/x/neo4j_driver_lite@VERSION/mod.ts"; |
17 | 34 | ```
|
18 | 35 |
|
19 |
| -The script will: |
| 36 | +Driver instance should be closed when application exits: |
20 | 37 |
|
21 |
| -1. Copy `neo4j-driver-lite` and the Neo4j packages it uses into a subfolder here |
22 |
| - called `lib`. |
23 |
| -1. Rewrite all imports to Deno-compatible versions |
24 |
| -1. Replace the "node channel" with the "deno channel" |
25 |
| -1. Test that the resulting driver can be imported by Deno and passes type checks |
| 38 | +```javascript |
| 39 | +await driver.close() |
| 40 | +``` |
| 41 | +otherwise the application shutdown might hang or exit with a non-zero exit code. |
26 | 42 |
|
27 |
| -It is not necessary to do any other setup first; in particular, you don't need |
28 |
| -to install any of the Node packages or run any of the driver monorepo's other |
29 |
| -scripts. However, you do need to have Deno installed. |
| 43 | +Application which uses the should use `--allow-net --allow-sys...` for running. |
| 44 | +For Deno versions bellow `1.27.1`, you should use the flag `--allow-env` instead of `--allow-sys`. |
30 | 45 |
|
31 |
| -## Usage instructions |
| 46 | +### TLS |
32 | 47 |
|
33 |
| -Once the driver is generated in the `lib` directory, you can import it and use |
34 |
| -it as you would use `neo4j-driver-lite` (refer to its documentation). |
| 48 | +For using system certificates, the `DENO_TLS_CA_STORE` should be set to `"system"`. |
| 49 | +`TRUST_ALL_CERTIFICATES` should be handle by `--unsafely-ignore-certificate-errors` and not by driver configuration. See, https://deno.com/blog/v1.13#disable-tls-verification; |
35 | 50 |
|
36 |
| -Here is an example: |
| 51 | +### Basic Example |
37 | 52 |
|
38 | 53 | ```typescript
|
39 |
| -import neo4j from "./lib/mod.ts"; |
40 | 54 | const URI = "bolt://localhost:7687";
|
41 | 55 | const driver = neo4j.driver(URI, neo4j.auth.basic("neo4j", "driverdemo"));
|
42 |
| -const session = driver.session(); |
43 | 56 |
|
44 |
| -const results = await session.run("MATCH (n) RETURN n LIMIT 25"); |
45 |
| -console.log(results.records); |
| 57 | +const { records } = await driver.executeQuery("MATCH (n) RETURN n LIMIT 25"); |
| 58 | +console.log(records); |
46 | 59 |
|
47 |
| -await session.close(); |
48 | 60 | await driver.close();
|
| 61 | + |
49 | 62 | ```
|
50 | 63 |
|
51 |
| -You can use `deno run --allow-net --allow-sys...` or `deno repl` to run this example. |
| 64 | +### Numbers and the Integer type |
52 | 65 |
|
53 |
| -For Deno versions bellow `1.27.1`, you should use the flag `--allow-env` instead of `--allow-sys`. |
| 66 | +The Neo4j type system uses 64-bit signed integer values. The range of values is between `-(2`<sup>`64`</sup>`- 1)` and `(2`<sup>`63`</sup>`- 1)`. |
54 | 67 |
|
55 |
| -If you don't have a running Neo4j instance, you can use |
56 |
| -`docker run --rm -p 7687:7687 -e NEO4J_AUTH=neo4j/driverdemo neo4j:4.4` to |
57 |
| -quickly spin one up. |
| 68 | +However, JavaScript can only safely represent integers between `Number.MIN_SAFE_INTEGER` `-(2`<sup>`53`</sup>`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`<sup>`53`</sup>`- 1)`. |
58 | 69 |
|
59 |
| -## TLS |
| 70 | +In order to support the full Neo4j type system, the driver will not automatically convert to javascript integers. |
| 71 | +Any time the driver receives an integer value from Neo4j, it will be represented with an internal integer type by the driver. |
60 | 72 |
|
61 |
| -For using system certificates, the `DENO_TLS_CA_STORE` should be set to `"system"`. |
62 |
| -`TRUST_ALL_CERTIFICATES` should be handle by `--unsafely-ignore-certificate-errors` and not by driver configuration. See, https://deno.com/blog/v1.13#disable-tls-verification; |
| 73 | +_**Any javascript number value passed as a parameter will be recognized as `Float` type.**_ |
| 74 | + |
| 75 | +#### Writing integers |
| 76 | + |
| 77 | +Numbers written directly e.g. `session.run("CREATE (n:Node {age: $age})", {age: 22})` will be of type `Float` in Neo4j. |
| 78 | + |
| 79 | +To write the `age` as an integer the `neo4j.int` method should be used: |
| 80 | + |
| 81 | +```javascript |
| 82 | +session.run('CREATE (n {age: $myIntParam})', { myIntParam: neo4j.int(22) }) |
| 83 | +``` |
| 84 | + |
| 85 | +To write an integer value that are not within the range of `Number.MIN_SAFE_INTEGER` `-(2`<sup>`53`</sup>`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`<sup>`53`</sup>`- 1)`, use a string argument to `neo4j.int`: |
| 86 | + |
| 87 | +```javascript |
| 88 | +session.run('CREATE (n {age: $myIntParam})', { |
| 89 | + myIntParam: neo4j.int('9223372036854775807') |
| 90 | +}) |
| 91 | +``` |
| 92 | + |
| 93 | +#### Reading integers |
| 94 | + |
| 95 | +In Neo4j, the type Integer can be larger what can be represented safely as an integer with JavaScript Number. |
| 96 | + |
| 97 | +It is only safe to convert to a JavaScript Number if you know that the number will be in the range `Number.MIN_SAFE_INTEGER` `-(2`<sup>`53`</sup>`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`<sup>`53`</sup>`- 1)`. |
| 98 | + |
| 99 | +In order to facilitate working with integers the driver include `neo4j.isInt`, `neo4j.integer.inSafeRange`, `neo4j.integer.toNumber`, and `neo4j.integer.toString`. |
| 100 | + |
| 101 | +```javascript |
| 102 | +var smallInteger = neo4j.int(123) |
| 103 | +if (neo4j.integer.inSafeRange(smallInteger)) { |
| 104 | + var aNumber = smallInteger.toNumber() |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +If you will be handling integers that is not within the JavaScript safe range of integers, you should convert the value to a string: |
| 109 | + |
| 110 | +```javascript |
| 111 | +var largeInteger = neo4j.int('9223372036854775807') |
| 112 | +if (!neo4j.integer.inSafeRange(largeInteger)) { |
| 113 | + var integerAsString = largeInteger.toString() |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +#### Enabling native numbers |
| 118 | + |
| 119 | +Starting from 1.6 version of the driver it is possible to configure it to only return native numbers instead of custom `Integer` objects. |
| 120 | +The configuration option affects all integers returned by the driver. **Enabling this option can result in a loss of precision and incorrect numeric |
| 121 | +values being returned if the database contains integer numbers outside of the range** `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`. |
| 122 | +To enable potentially lossy integer values use the driver's configuration object: |
| 123 | + |
| 124 | +```javascript |
| 125 | +var driver = neo4j.driver( |
| 126 | + 'neo4j://localhost', |
| 127 | + neo4j.auth.basic('neo4j', 'password'), |
| 128 | + { disableLosslessIntegers: true } |
| 129 | +) |
| 130 | +``` |
63 | 131 |
|
0 commit comments