Skip to content

Commit ae705f7

Browse files
authored
update readme (#1249)
Replaces deprecated function use, and moves session.run usage examples down to not be the top example.
1 parent 2031e43 commit ae705f7

File tree

2 files changed

+78
-75
lines changed

2 files changed

+78
-75
lines changed

README.md

+74-74
Original file line numberDiff line numberDiff line change
@@ -188,76 +188,6 @@ var rxSession = driver.rxSession({
188188
})
189189
```
190190

191-
### Executing Queries
192-
193-
#### Consuming Records with Streaming API
194-
195-
```javascript
196-
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
197-
session
198-
.run('MERGE (alice:Person {name : $nameParam}) RETURN alice.name AS name', {
199-
nameParam: 'Alice'
200-
})
201-
.subscribe({
202-
onKeys: keys => {
203-
console.log(keys)
204-
},
205-
onNext: record => {
206-
console.log(record.get('name'))
207-
},
208-
onCompleted: () => {
209-
session.close() // returns a Promise
210-
},
211-
onError: error => {
212-
console.log(error)
213-
}
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
224-
225-
```javascript
226-
// the Promise way, where the complete result is collected before we act on it:
227-
session
228-
.run('MERGE (james:Person {name : $nameParam}) RETURN james.name AS name', {
229-
nameParam: 'James'
230-
})
231-
.then(result => {
232-
result.records.forEach(record => {
233-
console.log(record.get('name'))
234-
})
235-
})
236-
.catch(error => {
237-
console.log(error)
238-
})
239-
.then(() => session.close())
240-
```
241-
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-
261191
### Transaction functions
262192

263193
```javascript
@@ -276,7 +206,7 @@ neo4j.driver('neo4j://localhost', neo4j.auth.basic('neo4j', 'password'), {
276206
// It is possible to execute read transactions that will benefit from automatic
277207
// retries on both single instance ('bolt' URI scheme) and Causal Cluster
278208
// ('neo4j' URI scheme) and will get automatic load balancing in cluster deployments
279-
var readTxResultPromise = session.readTransaction(txc => {
209+
var readTxResultPromise = session.executeRead(txc => {
280210
// used transaction will be committed automatically, no need for explicit commit/rollback
281211

282212
var result = txc.run('MATCH (person:Person) RETURN person.name AS name')
@@ -300,7 +230,7 @@ readTxResultPromise
300230

301231
```javascript
302232
rxSession
303-
.readTransaction(txc =>
233+
.executeRead(txc =>
304234
txc
305235
.run('MATCH (person:Person) RETURN person.name AS name')
306236
.records()
@@ -318,7 +248,7 @@ rxSession
318248
```javascript
319249
// It is possible to execute write transactions that will benefit from automatic retries
320250
// on both single instance ('bolt' URI scheme) and Causal Cluster ('neo4j' URI scheme)
321-
var writeTxResultPromise = session.writeTransaction(async txc => {
251+
var writeTxResultPromise = session.executeWrite(async txc => {
322252
// used transaction will be committed automatically, no need for explicit commit/rollback
323253

324254
var result = await txc.run(
@@ -344,7 +274,7 @@ writeTxResultPromise
344274

345275
```javascript
346276
rxSession
347-
.writeTransaction(txc =>
277+
.executeWrite(txc =>
348278
txc
349279
.run("MERGE (alice:Person {name: 'James'}) RETURN alice.name AS name")
350280
.records()
@@ -357,6 +287,76 @@ rxSession
357287
})
358288
```
359289

290+
### Consuming Records
291+
292+
#### Consuming Records with Streaming API
293+
294+
```javascript
295+
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
296+
session
297+
.run('MERGE (alice:Person {name : $nameParam}) RETURN alice.name AS name', {
298+
nameParam: 'Alice'
299+
})
300+
.subscribe({
301+
onKeys: keys => {
302+
console.log(keys)
303+
},
304+
onNext: record => {
305+
console.log(record.get('name'))
306+
},
307+
onCompleted: () => {
308+
session.close() // returns a Promise
309+
},
310+
onError: error => {
311+
console.log(error)
312+
}
313+
})
314+
```
315+
316+
Subscriber API allows following combinations of `onKeys`, `onNext`, `onCompleted` and `onError` callback invocations:
317+
318+
- zero or one `onKeys`,
319+
- zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked in this case
320+
- 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.
321+
322+
#### Consuming Records with Promise API
323+
324+
```javascript
325+
// the Promise way, where the complete result is collected before we act on it:
326+
session
327+
.run('MERGE (james:Person {name : $nameParam}) RETURN james.name AS name', {
328+
nameParam: 'James'
329+
})
330+
.then(result => {
331+
result.records.forEach(record => {
332+
console.log(record.get('name'))
333+
})
334+
})
335+
.catch(error => {
336+
console.log(error)
337+
})
338+
.then(() => session.close())
339+
```
340+
341+
#### Consuming Records with Reactive API
342+
343+
```javascript
344+
rxSession
345+
.run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {
346+
nameParam: 'Bob'
347+
})
348+
.records()
349+
.pipe(
350+
map(record => record.get('name')),
351+
concatWith(rxSession.close())
352+
)
353+
.subscribe({
354+
next: data => console.log(data),
355+
complete: () => console.log('completed'),
356+
error: err => console.log(err)
357+
})
358+
```
359+
360360
### Explicit Transactions
361361

362362
#### With Async Session

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
"typescript": "^4.9.5"
1212
},
1313
"lint-staged": {
14-
"*.{js,md,html}": [
14+
"*.{js,html}": [
1515
"npm run standard",
1616
"git add"
1717
],
18+
"*.md": [
19+
"git add"
20+
],
1821
"packages/core/**/*.ts": [
1922
"npm run ts-standard::core",
2023
"git add"

0 commit comments

Comments
 (0)