neo4j-driver 2.0.0-alpha03 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +1 -1
- package/README.md +386 -155
- package/examples/neo4j.html +11 -8
- package/examples/node.js +7 -7
- package/lib/browser/neo4j-web.esm.js +33956 -0
- package/lib/browser/neo4j-web.esm.min.js +1 -0
- package/lib/browser/neo4j-web.js +33955 -16863
- package/lib/browser/neo4j-web.min.js +1 -1
- package/lib/docs.js +37 -0
- package/lib/driver.js +66 -222
- package/lib/index.js +505 -389
- package/lib/internal/retry-logic-rx.js +91 -0
- package/lib/internal/server-version.js +80 -119
- package/lib/result-rx.js +379 -0
- package/lib/session-rx.js +239 -0
- package/lib/transaction-managed-rx.js +64 -0
- package/lib/transaction-rx.js +122 -0
- package/lib/version.js +5 -10
- package/package.json +43 -63
- package/spec/support/jasmine.json +0 -1
- package/tsconfig.json +6 -2
- package/types/driver.d.ts +14 -53
- package/types/index.d.ts +181 -72
- package/types/{statement-runner.d.ts → query-runner.d.ts} +6 -7
- package/{lib/internal/constants.js → types/result-rx.d.ts} +19 -12
- package/types/session-rx.d.ts +67 -0
- package/types/{transaction.d.ts → transaction-managed-rx.d.ts} +6 -11
- package/types/{spatial-types.d.ts → transaction-rx.d.ts} +13 -12
- package/.eslintrc.json +0 -23
- package/CONTRIBUTING.md +0 -60
- package/ISSUE_TEMPLATE.md +0 -53
- package/lib/error.js +0 -99
- package/lib/graph-types.js +0 -231
- package/lib/integer.js +0 -1150
- package/lib/internal/bolt-protocol-util.js +0 -62
- package/lib/internal/bolt-protocol-v1.js +0 -227
- package/lib/internal/bolt-protocol-v2.js +0 -68
- package/lib/internal/bolt-protocol-v3.js +0 -157
- package/lib/internal/bolt-protocol-v4.js +0 -94
- package/lib/internal/bookmark.js +0 -193
- package/lib/internal/browser/browser-buf.js +0 -118
- package/lib/internal/browser/browser-channel.js +0 -351
- package/lib/internal/browser/browser-host-name-resolver.js +0 -59
- package/lib/internal/browser/browser-utf8.js +0 -59
- package/lib/internal/browser/index.js +0 -57
- package/lib/internal/buf/base-buf.js +0 -517
- package/lib/internal/buf/combined-buf.js +0 -111
- package/lib/internal/channel-config.js +0 -103
- package/lib/internal/chunking.js +0 -271
- package/lib/internal/connection-channel.js +0 -617
- package/lib/internal/connection-delegate.js +0 -141
- package/lib/internal/connection-error-handler.js +0 -98
- package/lib/internal/connection-holder.js +0 -226
- package/lib/internal/connection-provider-direct.js +0 -79
- package/lib/internal/connection-provider-pooled.js +0 -175
- package/lib/internal/connection-provider-routing.js +0 -417
- package/lib/internal/connection-provider-single.js +0 -65
- package/lib/internal/connection-provider.js +0 -53
- package/lib/internal/connection.js +0 -167
- package/lib/internal/connectivity-verifier.js +0 -101
- package/lib/internal/least-connected-load-balancing-strategy.js +0 -119
- package/lib/internal/load-balancing-strategy.js +0 -69
- package/lib/internal/logger.js +0 -268
- package/lib/internal/node/index.js +0 -57
- package/lib/internal/node/node-buf.js +0 -124
- package/lib/internal/node/node-channel.js +0 -313
- package/lib/internal/node/node-host-name-resolver.js +0 -74
- package/lib/internal/node/node-utf8.js +0 -114
- package/lib/internal/packstream-v1.js +0 -831
- package/lib/internal/packstream-v2.js +0 -512
- package/lib/internal/pool-config.js +0 -73
- package/lib/internal/pool.js +0 -435
- package/lib/internal/protocol-handshaker.js +0 -146
- package/lib/internal/rediscovery.js +0 -106
- package/lib/internal/request-message.js +0 -343
- package/lib/internal/resolver/base-host-name-resolver.js +0 -57
- package/lib/internal/resolver/configured-custom-resolver.js +0 -67
- package/lib/internal/round-robin-array-index.js +0 -70
- package/lib/internal/routing-table.js +0 -116
- package/lib/internal/routing-util.js +0 -185
- package/lib/internal/server-address.js +0 -94
- package/lib/internal/stream-observer.js +0 -220
- package/lib/internal/temporal-util.js +0 -613
- package/lib/internal/transaction-executor.js +0 -239
- package/lib/internal/tx-config.js +0 -134
- package/lib/internal/url-util.js +0 -230
- package/lib/internal/util.js +0 -156
- package/lib/record.js +0 -165
- package/lib/result-summary.js +0 -437
- package/lib/result.js +0 -217
- package/lib/routing-driver.js +0 -120
- package/lib/session.js +0 -380
- package/lib/spatial-types.js +0 -88
- package/lib/temporal-types.js +0 -459
- package/lib/transaction.js +0 -387
- package/support/inject-browser-transform.js +0 -20
- package/types/error.d.ts +0 -39
- package/types/graph-types.d.ts +0 -84
- package/types/integer.d.ts +0 -147
- package/types/record.d.ts +0 -41
- package/types/result-summary.d.ts +0 -117
- package/types/result.d.ts +0 -39
- package/types/session.d.ts +0 -58
- package/types/temporal-types.d.ts +0 -156
package/README.md
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
# Neo4j Driver for JavaScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is the official Neo4j driver for JavaScript.
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
See also: https://neo4j.com/developer/kb/neo4j-supported-versions/
|
|
4
10
|
|
|
5
11
|
Resources to get you started:
|
|
6
12
|
|
|
7
|
-
- [
|
|
8
|
-
- [Sample small project using the driver](https://github.com/neo4j-examples/movies-javascript-bolt)
|
|
9
|
-
- [Sample application using the driver](https://github.com/neo4j-examples/neo4j-movies-template)
|
|
13
|
+
- [API Documentation](https://neo4j.com/docs/api/javascript-driver/current/)
|
|
10
14
|
- [Neo4j Manual](https://neo4j.com/docs/)
|
|
11
15
|
- [Neo4j Refcard](https://neo4j.com/docs/cypher-refcard/current/)
|
|
12
16
|
|
|
13
|
-
##
|
|
17
|
+
## What's New in 5.x
|
|
18
|
+
|
|
19
|
+
- [Changelog](https://github.com/neo4j/neo4j-javascript-driver/wiki/5.0-changelog)
|
|
20
|
+
|
|
21
|
+
## Including the Driver
|
|
22
|
+
|
|
23
|
+
### In Node.js application
|
|
14
24
|
|
|
15
25
|
Stable channel:
|
|
16
26
|
|
|
@@ -34,12 +44,12 @@ var neo4j = require('neo4j-driver')
|
|
|
34
44
|
Driver instance should be closed when Node.js application exits:
|
|
35
45
|
|
|
36
46
|
```javascript
|
|
37
|
-
driver.close()
|
|
47
|
+
driver.close() // returns a Promise
|
|
38
48
|
```
|
|
39
49
|
|
|
40
50
|
otherwise application shutdown might hang or it might exit with a non-zero exit code.
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
### In web browser
|
|
43
53
|
|
|
44
54
|
We build a special browser version of the driver, which supports connecting to Neo4j over WebSockets.
|
|
45
55
|
It can be included in an HTML page using one of the following tags:
|
|
@@ -59,102 +69,217 @@ It can be included in an HTML page using one of the following tags:
|
|
|
59
69
|
<script src="https://cdn.jsdelivr.net/npm/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.min.js"></script>
|
|
60
70
|
```
|
|
61
71
|
|
|
62
|
-
This will make a global `neo4j` object available, where you can
|
|
72
|
+
This will make a global `neo4j` object available, where you can create a driver instance with `neo4j.driver`:
|
|
63
73
|
|
|
64
74
|
```javascript
|
|
65
75
|
var driver = neo4j.driver(
|
|
66
|
-
'
|
|
67
|
-
neo4j.auth.basic('neo4j', '
|
|
76
|
+
'neo4j://localhost',
|
|
77
|
+
neo4j.auth.basic('neo4j', 'password')
|
|
68
78
|
)
|
|
69
79
|
```
|
|
70
80
|
|
|
71
|
-
|
|
81
|
+
From `5.4.0`, this version is also exported as ECMA Script Module.
|
|
82
|
+
It can be imported from a module using the following statements:
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
// Direct reference
|
|
86
|
+
import neo4j from 'lib/browser/neo4j-web.esm.min.js'
|
|
87
|
+
|
|
88
|
+
// unpkg CDN non-minified , version X.Y.Z where X.Y.Z >= 5.4.0
|
|
89
|
+
import neo4j from 'https://unpkg.com/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.esm.js'
|
|
90
|
+
|
|
91
|
+
// unpkg CDN minified for production use, version X.Y.Z where X.Y.Z >= 5.4.0
|
|
92
|
+
import neo4j from 'https://unpkg.com/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.esm.min.js'
|
|
93
|
+
|
|
94
|
+
// jsDelivr CDN non-minified, version X.Y.Z where X.Y.Z >= 5.4.0
|
|
95
|
+
import neo4j from 'https://cdn.jsdelivr.net/npm/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.esm.js'
|
|
96
|
+
|
|
97
|
+
// jsDelivr CDN minified for production use, version X.Y.Z where X.Y.Z >= 5.4.0
|
|
98
|
+
import neo4j from 'https://cdn.jsdelivr.net/npm/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.esm.min.js'
|
|
99
|
+
|
|
100
|
+
```
|
|
72
101
|
|
|
73
102
|
It is not required to explicitly close the driver on a web page. Web browser should gracefully close all open
|
|
74
103
|
WebSockets when the page is unloaded. However, driver instance should be explicitly closed when it's lifetime
|
|
75
104
|
is not the same as the lifetime of the web page:
|
|
76
105
|
|
|
77
106
|
```javascript
|
|
78
|
-
driver.close()
|
|
107
|
+
driver.close() // returns a Promise
|
|
79
108
|
```
|
|
80
109
|
|
|
81
110
|
## Usage examples
|
|
82
111
|
|
|
83
|
-
Driver
|
|
112
|
+
### Constructing a Driver
|
|
84
113
|
|
|
85
114
|
```javascript
|
|
86
|
-
// Create a driver instance, for the user neo4j with password
|
|
115
|
+
// Create a driver instance, for the user `neo4j` with password `password`.
|
|
87
116
|
// It should be enough to have a single driver per database per application.
|
|
88
117
|
var driver = neo4j.driver(
|
|
89
|
-
'
|
|
90
|
-
neo4j.auth.basic('neo4j', '
|
|
118
|
+
'neo4j://localhost',
|
|
119
|
+
neo4j.auth.basic('neo4j', 'password')
|
|
91
120
|
)
|
|
92
121
|
|
|
93
122
|
// Close the driver when application exits.
|
|
94
123
|
// This closes all used network connections.
|
|
95
|
-
driver.close()
|
|
124
|
+
await driver.close()
|
|
96
125
|
```
|
|
97
126
|
|
|
98
|
-
Session
|
|
127
|
+
### Acquiring a Session
|
|
128
|
+
|
|
129
|
+
#### Regular Session
|
|
99
130
|
|
|
100
131
|
```javascript
|
|
101
132
|
// Create a session to run Cypher statements in.
|
|
102
133
|
// Note: Always make sure to close sessions when you are done using them!
|
|
103
134
|
var session = driver.session()
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
##### with a Default Access Mode of `READ`
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
var session = driver.session({ defaultAccessMode: neo4j.session.READ })
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
##### with Bookmarks
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
var session = driver.session({
|
|
147
|
+
bookmarks: [bookmark1FromPreviousSession, bookmark2FromPreviousSession]
|
|
148
|
+
})
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
##### against a Database
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
var session = driver.session({
|
|
155
|
+
database: 'foo',
|
|
156
|
+
defaultAccessMode: neo4j.session.WRITE
|
|
157
|
+
})
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Reactive Session
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
// Create a reactive session to run Cypher statements in.
|
|
164
|
+
// Note: Always make sure to close sessions when you are done using them!
|
|
165
|
+
var rxSession = driver.rxSession()
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
##### with a Default Access Mode of `READ`
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
var rxSession = driver.rxSession({ defaultAccessMode: neo4j.session.READ })
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
##### with Bookmarks
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
var rxSession = driver.rxSession({
|
|
178
|
+
bookmarks: [bookmark1FromPreviousSession, bookmark2FromPreviousSession]
|
|
179
|
+
})
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
##### against a Database
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
var rxSession = driver.rxSession({
|
|
186
|
+
database: 'foo',
|
|
187
|
+
defaultAccessMode: neo4j.session.WRITE
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Executing Queries
|
|
104
192
|
|
|
193
|
+
#### Consuming Records with Streaming API
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
105
196
|
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
|
|
106
197
|
session
|
|
107
|
-
.run('MERGE (alice:Person {name :
|
|
198
|
+
.run('MERGE (alice:Person {name : $nameParam}) RETURN alice.name AS name', {
|
|
108
199
|
nameParam: 'Alice'
|
|
109
200
|
})
|
|
110
201
|
.subscribe({
|
|
111
|
-
|
|
202
|
+
onKeys: keys => {
|
|
203
|
+
console.log(keys)
|
|
204
|
+
},
|
|
205
|
+
onNext: record => {
|
|
112
206
|
console.log(record.get('name'))
|
|
113
207
|
},
|
|
114
|
-
onCompleted:
|
|
115
|
-
session.close()
|
|
208
|
+
onCompleted: () => {
|
|
209
|
+
session.close() // returns a Promise
|
|
116
210
|
},
|
|
117
|
-
onError:
|
|
211
|
+
onError: error => {
|
|
118
212
|
console.log(error)
|
|
119
213
|
}
|
|
120
214
|
})
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Subscriber API allows following combinations of `onKeys`, `onNext`, `onCompleted` and `onError` callback invocations:
|
|
218
|
+
|
|
219
|
+
- zero or one `onKeys`,
|
|
220
|
+
- zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked in this case
|
|
221
|
+
- zero or more `onNext` followed by `onError` when operation failed. Callback `onError` might be invoked after couple `onNext` invocations because records are streamed lazily by the database. `onCompleted` will not be invoked in this case.
|
|
222
|
+
|
|
223
|
+
#### Consuming Records with Promise API
|
|
121
224
|
|
|
122
|
-
|
|
225
|
+
```javascript
|
|
123
226
|
// the Promise way, where the complete result is collected before we act on it:
|
|
124
227
|
session
|
|
125
|
-
.run('MERGE (james:Person {name :
|
|
228
|
+
.run('MERGE (james:Person {name : $nameParam}) RETURN james.name AS name', {
|
|
126
229
|
nameParam: 'James'
|
|
127
230
|
})
|
|
128
|
-
.then(
|
|
129
|
-
result.records.forEach(
|
|
231
|
+
.then(result => {
|
|
232
|
+
result.records.forEach(record => {
|
|
130
233
|
console.log(record.get('name'))
|
|
131
234
|
})
|
|
132
|
-
session.close()
|
|
133
235
|
})
|
|
134
|
-
.catch(
|
|
236
|
+
.catch(error => {
|
|
135
237
|
console.log(error)
|
|
136
238
|
})
|
|
239
|
+
.then(() => session.close())
|
|
137
240
|
```
|
|
138
241
|
|
|
139
|
-
|
|
242
|
+
#### Consuming Records with Reactive API
|
|
243
|
+
|
|
244
|
+
```javascript
|
|
245
|
+
rxSession
|
|
246
|
+
.run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {
|
|
247
|
+
nameParam: 'Bob'
|
|
248
|
+
})
|
|
249
|
+
.records()
|
|
250
|
+
.pipe(
|
|
251
|
+
map(record => record.get('name')),
|
|
252
|
+
concatWith(rxSession.close())
|
|
253
|
+
)
|
|
254
|
+
.subscribe({
|
|
255
|
+
next: data => console.log(data),
|
|
256
|
+
complete: () => console.log('completed'),
|
|
257
|
+
error: err => console.log(err)
|
|
258
|
+
})
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Transaction functions
|
|
140
262
|
|
|
141
263
|
```javascript
|
|
142
264
|
// Transaction functions provide a convenient API with minimal boilerplate and
|
|
143
265
|
// retries on network fluctuations and transient errors. Maximum retry time is
|
|
144
266
|
// configured on the driver level and is 30 seconds by default:
|
|
145
|
-
|
|
267
|
+
// Applies both to standard and reactive sessions.
|
|
268
|
+
neo4j.driver('neo4j://localhost', neo4j.auth.basic('neo4j', 'password'), {
|
|
146
269
|
maxTransactionRetryTime: 30000
|
|
147
270
|
})
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
#### Reading with Async Session
|
|
148
274
|
|
|
275
|
+
```javascript
|
|
149
276
|
// It is possible to execute read transactions that will benefit from automatic
|
|
150
277
|
// retries on both single instance ('bolt' URI scheme) and Causal Cluster
|
|
151
278
|
// ('neo4j' URI scheme) and will get automatic load balancing in cluster deployments
|
|
152
|
-
var readTxResultPromise = session.readTransaction(
|
|
279
|
+
var readTxResultPromise = session.readTransaction(txc => {
|
|
153
280
|
// used transaction will be committed automatically, no need for explicit commit/rollback
|
|
154
281
|
|
|
155
|
-
var result =
|
|
156
|
-
'MATCH (person:Person) RETURN person.name AS name'
|
|
157
|
-
)
|
|
282
|
+
var result = txc.run('MATCH (person:Person) RETURN person.name AS name')
|
|
158
283
|
// at this point it is possible to either return the result or process it and return the
|
|
159
284
|
// result of processing it is also possible to run more statements in the same transaction
|
|
160
285
|
return result
|
|
@@ -162,190 +287,209 @@ var readTxResultPromise = session.readTransaction(function(transaction) {
|
|
|
162
287
|
|
|
163
288
|
// returned Promise can be later consumed like this:
|
|
164
289
|
readTxResultPromise
|
|
165
|
-
.then(
|
|
166
|
-
session.close()
|
|
290
|
+
.then(result => {
|
|
167
291
|
console.log(result.records)
|
|
168
292
|
})
|
|
169
|
-
.catch(
|
|
293
|
+
.catch(error => {
|
|
170
294
|
console.log(error)
|
|
171
295
|
})
|
|
296
|
+
.then(() => session.close())
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
#### Reading with Reactive Session
|
|
300
|
+
|
|
301
|
+
```javascript
|
|
302
|
+
rxSession
|
|
303
|
+
.readTransaction(txc =>
|
|
304
|
+
txc
|
|
305
|
+
.run('MATCH (person:Person) RETURN person.name AS name')
|
|
306
|
+
.records()
|
|
307
|
+
.pipe(map(record => record.get('name')))
|
|
308
|
+
)
|
|
309
|
+
.subscribe({
|
|
310
|
+
next: data => console.log(data),
|
|
311
|
+
complete: () => console.log('completed'),
|
|
312
|
+
error: err => console.log(error)
|
|
313
|
+
})
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
#### Writing with Async Session
|
|
172
317
|
|
|
318
|
+
```javascript
|
|
173
319
|
// It is possible to execute write transactions that will benefit from automatic retries
|
|
174
320
|
// on both single instance ('bolt' URI scheme) and Causal Cluster ('neo4j' URI scheme)
|
|
175
|
-
var writeTxResultPromise = session.writeTransaction(
|
|
321
|
+
var writeTxResultPromise = session.writeTransaction(async txc => {
|
|
176
322
|
// used transaction will be committed automatically, no need for explicit commit/rollback
|
|
177
323
|
|
|
178
|
-
var result =
|
|
179
|
-
"MERGE (alice:Person {name : 'Alice'
|
|
324
|
+
var result = await txc.run(
|
|
325
|
+
"MERGE (alice:Person {name : 'Alice'}) RETURN alice.name AS name"
|
|
180
326
|
)
|
|
181
327
|
// at this point it is possible to either return the result or process it and return the
|
|
182
328
|
// result of processing it is also possible to run more statements in the same transaction
|
|
183
|
-
return result.records.map(
|
|
184
|
-
return record.get('name')
|
|
185
|
-
})
|
|
329
|
+
return result.records.map(record => record.get('name'))
|
|
186
330
|
})
|
|
187
331
|
|
|
188
332
|
// returned Promise can be later consumed like this:
|
|
189
333
|
writeTxResultPromise
|
|
190
|
-
.then(
|
|
191
|
-
session.close()
|
|
334
|
+
.then(namesArray => {
|
|
192
335
|
console.log(namesArray)
|
|
193
336
|
})
|
|
194
|
-
.catch(
|
|
337
|
+
.catch(error => {
|
|
195
338
|
console.log(error)
|
|
196
339
|
})
|
|
340
|
+
.then(() => session.close())
|
|
197
341
|
```
|
|
198
342
|
|
|
199
|
-
|
|
343
|
+
#### Writing with Reactive Session
|
|
200
344
|
|
|
201
345
|
```javascript
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
console.log(
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
console.log(error)
|
|
216
|
-
}
|
|
217
|
-
})
|
|
346
|
+
rxSession
|
|
347
|
+
.writeTransaction(txc =>
|
|
348
|
+
txc
|
|
349
|
+
.run("MERGE (alice:Person {name: 'James'}) RETURN alice.name AS name")
|
|
350
|
+
.records()
|
|
351
|
+
.pipe(map(record => record.get('name')))
|
|
352
|
+
)
|
|
353
|
+
.subscribe({
|
|
354
|
+
next: data => console.log(data),
|
|
355
|
+
complete: () => console.log('completed'),
|
|
356
|
+
error: error => console.log(error)
|
|
357
|
+
})
|
|
358
|
+
```
|
|
218
359
|
|
|
219
|
-
|
|
220
|
-
nameParam: 'Adam'
|
|
221
|
-
}).subscribe({
|
|
222
|
-
onNext: function(record) {
|
|
223
|
-
console.log(record.get('name'))
|
|
224
|
-
},
|
|
225
|
-
onCompleted: function() {
|
|
226
|
-
console.log('Second query completed')
|
|
227
|
-
},
|
|
228
|
-
onError: function(error) {
|
|
229
|
-
console.log(error)
|
|
230
|
-
}
|
|
231
|
-
})
|
|
360
|
+
### Explicit Transactions
|
|
232
361
|
|
|
233
|
-
|
|
234
|
-
var success = false
|
|
362
|
+
#### With Async Session
|
|
235
363
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
|
|
364
|
+
```javascript
|
|
365
|
+
// run statement in a transaction
|
|
366
|
+
const txc = session.beginTransaction()
|
|
367
|
+
try {
|
|
368
|
+
const result1 = await txc.run(
|
|
369
|
+
'MERGE (bob:Person {name: $nameParam}) RETURN bob.name AS name',
|
|
370
|
+
{
|
|
371
|
+
nameParam: 'Bob'
|
|
244
372
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
373
|
+
)
|
|
374
|
+
result1.records.forEach(r => console.log(r.get('name')))
|
|
375
|
+
console.log('First query completed')
|
|
376
|
+
|
|
377
|
+
const result2 = await txc.run(
|
|
378
|
+
'MERGE (adam:Person {name: $nameParam}) RETURN adam.name AS name',
|
|
379
|
+
{
|
|
380
|
+
nameParam: 'Adam'
|
|
381
|
+
}
|
|
382
|
+
)
|
|
383
|
+
result2.records.forEach(r => console.log(r.get('name')))
|
|
384
|
+
console.log('Second query completed')
|
|
385
|
+
|
|
386
|
+
await txc.commit()
|
|
387
|
+
console.log('committed')
|
|
388
|
+
} catch (error) {
|
|
389
|
+
console.log(error)
|
|
390
|
+
await txc.rollback()
|
|
248
391
|
console.log('rolled back')
|
|
249
|
-
|
|
392
|
+
} finally {
|
|
393
|
+
await session.close()
|
|
250
394
|
}
|
|
251
395
|
```
|
|
252
396
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
- zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked
|
|
256
|
-
in this case
|
|
257
|
-
- zero or more `onNext` followed by `onError` when operation failed. Callback `onError` might be invoked after
|
|
258
|
-
couple `onNext` invocations because records are streamed lazily by the database. `onCompleted` will not be invoked
|
|
259
|
-
in this case
|
|
397
|
+
#### With Reactive Session
|
|
260
398
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
399
|
+
```javascript
|
|
400
|
+
rxSession
|
|
401
|
+
.beginTransaction()
|
|
402
|
+
.pipe(
|
|
403
|
+
mergeMap(txc =>
|
|
404
|
+
concatWith(
|
|
405
|
+
txc
|
|
406
|
+
.run(
|
|
407
|
+
'MERGE (bob:Person {name: $nameParam}) RETURN bob.name AS name',
|
|
408
|
+
{
|
|
409
|
+
nameParam: 'Bob'
|
|
410
|
+
}
|
|
411
|
+
)
|
|
412
|
+
.records()
|
|
413
|
+
.pipe(map(r => r.get('name'))),
|
|
414
|
+
of('First query completed'),
|
|
415
|
+
txc
|
|
416
|
+
.run(
|
|
417
|
+
'MERGE (adam:Person {name: $nameParam}) RETURN adam.name AS name',
|
|
418
|
+
{
|
|
419
|
+
nameParam: 'Adam'
|
|
420
|
+
}
|
|
421
|
+
)
|
|
422
|
+
.records()
|
|
423
|
+
.pipe(map(r => r.get('name'))),
|
|
424
|
+
of('Second query completed'),
|
|
425
|
+
txc.commit(),
|
|
426
|
+
of('committed')
|
|
427
|
+
).pipe(catchError(err => txc.rollback().pipe(throwError(() => err))))
|
|
428
|
+
)
|
|
429
|
+
)
|
|
430
|
+
.subscribe({
|
|
431
|
+
next: data => console.log(data),
|
|
432
|
+
complete: () => console.log('completed'),
|
|
433
|
+
error: error => console.log(error)
|
|
434
|
+
})
|
|
435
|
+
```
|
|
293
436
|
|
|
294
|
-
###
|
|
437
|
+
### Numbers and the Integer type
|
|
295
438
|
|
|
296
|
-
|
|
297
|
-
To run the same test suite, run `.\runTest.ps1` instead in powershell with admin right.
|
|
298
|
-
The admin right is required to start/stop Neo4j properly as a system service.
|
|
299
|
-
While there is no need to grab admin right if you are running tests against an existing Neo4j server using `npm test`.
|
|
439
|
+
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)`.
|
|
300
440
|
|
|
301
|
-
|
|
441
|
+
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)`.
|
|
302
442
|
|
|
303
|
-
The Neo4j type system includes 64-bit integer values.
|
|
304
|
-
However, JavaScript can only safely represent integers between `-(2`<sup>`53`</sup>`- 1)` and `(2`<sup>`53`</sup>`- 1)`.
|
|
305
443
|
In order to support the full Neo4j type system, the driver will not automatically convert to javascript integers.
|
|
306
444
|
Any time the driver receives an integer value from Neo4j, it will be represented with an internal integer type by the driver.
|
|
307
445
|
|
|
308
|
-
|
|
446
|
+
_**Any javascript number value passed as a parameter will be recognized as `Float` type.**_
|
|
447
|
+
|
|
448
|
+
#### Writing integers
|
|
449
|
+
|
|
450
|
+
Numbers written directly e.g. `session.run("CREATE (n:Node {age: $age})", {age: 22})` will be of type `Float` in Neo4j.
|
|
309
451
|
|
|
310
|
-
Number written directly e.g. `session.run("CREATE (n:Node {age: {age}})", {age: 22})` will be of type `Float` in Neo4j.
|
|
311
452
|
To write the `age` as an integer the `neo4j.int` method should be used:
|
|
312
453
|
|
|
313
454
|
```javascript
|
|
314
455
|
var neo4j = require('neo4j-driver')
|
|
315
456
|
|
|
316
|
-
session.run('CREATE (n {age:
|
|
457
|
+
session.run('CREATE (n {age: $myIntParam})', { myIntParam: neo4j.int(22) })
|
|
317
458
|
```
|
|
318
459
|
|
|
319
|
-
To write
|
|
460
|
+
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`:
|
|
320
461
|
|
|
321
462
|
```javascript
|
|
322
|
-
session.run('CREATE (n {age:
|
|
463
|
+
session.run('CREATE (n {age: $myIntParam})', {
|
|
323
464
|
myIntParam: neo4j.int('9223372036854775807')
|
|
324
465
|
})
|
|
325
466
|
```
|
|
326
467
|
|
|
327
|
-
|
|
468
|
+
#### Reading integers
|
|
469
|
+
|
|
470
|
+
In Neo4j, the type Integer can be larger what can be represented safely as an integer with JavaScript Number.
|
|
471
|
+
|
|
472
|
+
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)`.
|
|
328
473
|
|
|
329
|
-
Since Integers can be larger than can be represented as JavaScript numbers, it is only safe to convert to JavaScript numbers if you know that they will not exceed `(2`<sup>`53`</sup>`- 1)` in size.
|
|
330
474
|
In order to facilitate working with integers the driver include `neo4j.isInt`, `neo4j.integer.inSafeRange`, `neo4j.integer.toNumber`, and `neo4j.integer.toString`.
|
|
331
475
|
|
|
332
476
|
```javascript
|
|
333
|
-
var
|
|
334
|
-
if (neo4j.integer.inSafeRange(
|
|
335
|
-
var aNumber =
|
|
477
|
+
var smallInteger = neo4j.int(123)
|
|
478
|
+
if (neo4j.integer.inSafeRange(smallInteger)) {
|
|
479
|
+
var aNumber = smallInteger.toNumber()
|
|
336
480
|
}
|
|
337
481
|
```
|
|
338
482
|
|
|
339
|
-
If you will be handling integers
|
|
483
|
+
If you will be handling integers that is not within the JavaScript safe range of integers, you should convert the value to a string:
|
|
340
484
|
|
|
341
485
|
```javascript
|
|
342
|
-
var
|
|
343
|
-
if (!neo4j.integer.inSafeRange(
|
|
344
|
-
var integerAsString =
|
|
486
|
+
var largeInteger = neo4j.int('9223372036854775807')
|
|
487
|
+
if (!neo4j.integer.inSafeRange(largeInteger)) {
|
|
488
|
+
var integerAsString = largeInteger.toString()
|
|
345
489
|
}
|
|
346
490
|
```
|
|
347
491
|
|
|
348
|
-
|
|
492
|
+
#### Enabling native numbers
|
|
349
493
|
|
|
350
494
|
Starting from 1.6 version of the driver it is possible to configure it to only return native numbers instead of custom `Integer` objects.
|
|
351
495
|
The configuration option affects all integers returned by the driver. **Enabling this option can result in a loss of precision and incorrect numeric
|
|
@@ -354,8 +498,95 @@ To enable potentially lossy integer values use the driver's configuration object
|
|
|
354
498
|
|
|
355
499
|
```javascript
|
|
356
500
|
var driver = neo4j.driver(
|
|
357
|
-
'
|
|
358
|
-
neo4j.auth.basic('neo4j', '
|
|
501
|
+
'neo4j://localhost',
|
|
502
|
+
neo4j.auth.basic('neo4j', 'password'),
|
|
359
503
|
{ disableLosslessIntegers: true }
|
|
360
504
|
)
|
|
361
505
|
```
|
|
506
|
+
|
|
507
|
+
## Building
|
|
508
|
+
|
|
509
|
+
```
|
|
510
|
+
npm ci
|
|
511
|
+
npm run build
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
This produces browser-compatible standalone files under `lib/browser` and a Node.js module version under `lib/`.
|
|
515
|
+
See files under `examples/` on how to use.
|
|
516
|
+
|
|
517
|
+
## Testing
|
|
518
|
+
|
|
519
|
+
Tests **require** latest [Testkit 4.3](https://github.com/neo4j-drivers/testkit/tree/4.3), Python3 and Docker.
|
|
520
|
+
|
|
521
|
+
Testkit is needed to be cloned and configured to run against the Javascript Lite Driver. Use the following steps to configure Testkit.
|
|
522
|
+
|
|
523
|
+
1. Clone the Testkit repository
|
|
524
|
+
|
|
525
|
+
```
|
|
526
|
+
git clone https://github.com/neo4j-drivers/testkit.git
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
2. Under the Testkit folder, install the requirements.
|
|
530
|
+
|
|
531
|
+
```
|
|
532
|
+
pip3 install -r requirements.txt
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
3. Define some enviroment variables to configure Testkit
|
|
536
|
+
|
|
537
|
+
```
|
|
538
|
+
export TEST_DRIVER_NAME=javascript
|
|
539
|
+
export TEST_DRIVER_REPO=<path for the root folder of driver repository>
|
|
540
|
+
unset TEST_DRIVER_LITE
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
To run test against against some Neo4j version:
|
|
544
|
+
|
|
545
|
+
```
|
|
546
|
+
python3 main.py
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
More details about how to use Teskit could be found on [its repository](https://github.com/neo4j-drivers/testkit/tree/4.3)
|
|
550
|
+
|
|
551
|
+
## Testing (Legacy)
|
|
552
|
+
|
|
553
|
+
Tests **require** latest [Boltkit](https://github.com/neo4j-contrib/boltkit) and [Firefox](https://www.mozilla.org/firefox/) to be installed in the system.
|
|
554
|
+
|
|
555
|
+
Boltkit is needed to start, stop and configure local test database. Boltkit can be installed with the following command:
|
|
556
|
+
|
|
557
|
+
```
|
|
558
|
+
pip3 install --upgrade boltkit
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
To run tests against "default" Neo4j version:
|
|
562
|
+
|
|
563
|
+
```
|
|
564
|
+
./runTests.sh
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
To run tests against specified Neo4j version:
|
|
568
|
+
|
|
569
|
+
```
|
|
570
|
+
./runTests.sh '-e 4.2.0'
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Simple `npm test` can also be used if you already have a running version of a compatible Neo4j server.
|
|
574
|
+
|
|
575
|
+
For development, you can have the build tool rerun the tests each time you change
|
|
576
|
+
the source code:
|
|
577
|
+
|
|
578
|
+
```
|
|
579
|
+
gulp watch-n-test
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
If the `gulp` command line tool is not available, you might need to install this globally:
|
|
583
|
+
|
|
584
|
+
```
|
|
585
|
+
npm install -g gulp-cli
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### Testing on windows
|
|
589
|
+
|
|
590
|
+
To run the same test suite, run `.\runTest.ps1` instead in powershell with admin right.
|
|
591
|
+
The admin right is required to start/stop Neo4j properly as a system service.
|
|
592
|
+
While there is no need to grab admin right if you are running tests against an existing Neo4j server using `npm test`.
|