Skip to content

Commit ae8396c

Browse files
committed
Descibe autocommit tx and executequery
1 parent f6b1b2f commit ae8396c

File tree

2 files changed

+204
-126
lines changed

2 files changed

+204
-126
lines changed

README.md

Lines changed: 102 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -287,77 +287,43 @@ rxSession
287287
})
288288
```
289289

290-
### Consuming Records
291-
292-
#### Consuming Records with Streaming API
290+
### ExecuteQuery Function
293291

294292
```javascript
295-
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
296-
driver
297-
.executeQuery('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)
293+
// Since 5.8.0, the driver has offered a way to run a single query transaction with minimal boilerplate.
294+
// The driver.executeQuery() function features the same automatic retries as transaction functions.
295+
//
296+
var executeQueryResultPromise = driver
297+
.executeQuery(
298+
"MATCH (alice:Person {name: $nameParam}) RETURN alice.DOB AS DateOfBirth",
299+
{
300+
nameParam: 'Alice'
301+
},
302+
{
303+
routing: 'READ',
304+
database: 'neo4j'
312305
}
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-
driver
327-
.executeQuery('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())
306+
)
339307
```
340308

341-
#### Consuming Records with Reactive API
309+
### Auto-Commit/Implicit Transaction
342310

343311
```javascript
344-
rxSession
345-
.executeRead(txc =>
346-
txc
347-
.run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {
348-
nameParam: 'Bob'
349-
})
350-
)
351-
.records()
352-
.pipe(
353-
map(record => record.get('name')),
354-
concatWith(rxSession.close())
312+
// This is the most basic and limited form with which to run a Cypher query.
313+
// The driver will not automatically retry implicit transactions.
314+
// This function should only be used when the other driver query interfaces do not fit the purpose.
315+
// Implicit transactions are the only ones that can be used for CALL { …​ } IN TRANSACTIONS queries.
316+
317+
var implicitTxResultPromise = session
318+
.run(
319+
"CALL { …​ } IN TRANSACTIONS",
320+
{
321+
param1: 'param'
322+
},
323+
{
324+
database: 'neo4j'
325+
}
355326
)
356-
.subscribe({
357-
next: data => console.log(data),
358-
complete: () => console.log('completed'),
359-
error: err => console.log(err)
360-
})
361327
```
362328

363329
### Explicit Transactions
@@ -437,6 +403,79 @@ rxSession
437403
})
438404
```
439405

406+
### Consuming Records
407+
408+
#### Consuming Records with Streaming API
409+
410+
```javascript
411+
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
412+
driver
413+
.executeQuery('MERGE (alice:Person {name : $nameParam}) RETURN alice.name AS name', {
414+
nameParam: 'Alice'
415+
})
416+
.subscribe({
417+
onKeys: keys => {
418+
console.log(keys)
419+
},
420+
onNext: record => {
421+
console.log(record.get('name'))
422+
},
423+
onCompleted: () => {
424+
session.close() // returns a Promise
425+
},
426+
onError: error => {
427+
console.log(error)
428+
}
429+
})
430+
```
431+
432+
Subscriber API allows following combinations of `onKeys`, `onNext`, `onCompleted` and `onError` callback invocations:
433+
434+
- zero or one `onKeys`,
435+
- zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked in this case
436+
- 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.
437+
438+
#### Consuming Records with Promise API
439+
440+
```javascript
441+
// the Promise way, where the complete result is collected before we act on it:
442+
driver
443+
.executeQuery('MERGE (james:Person {name : $nameParam}) RETURN james.name AS name', {
444+
nameParam: 'James'
445+
})
446+
.then(result => {
447+
result.records.forEach(record => {
448+
console.log(record.get('name'))
449+
})
450+
})
451+
.catch(error => {
452+
console.log(error)
453+
})
454+
.then(() => session.close())
455+
```
456+
457+
#### Consuming Records with Reactive API
458+
459+
```javascript
460+
rxSession
461+
.executeRead(txc =>
462+
txc
463+
.run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {
464+
nameParam: 'Bob'
465+
})
466+
)
467+
.records()
468+
.pipe(
469+
map(record => record.get('name')),
470+
concatWith(rxSession.close())
471+
)
472+
.subscribe({
473+
next: data => console.log(data),
474+
complete: () => console.log('completed'),
475+
error: err => console.log(err)
476+
})
477+
```
478+
440479
### Numbers and the Integer type
441480

442481
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)`.

packages/neo4j-driver/README.md

Lines changed: 102 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -287,77 +287,43 @@ rxSession
287287
})
288288
```
289289

290-
### Consuming Records
291-
292-
#### Consuming Records with Streaming API
290+
### ExecuteQuery Function
293291

294292
```javascript
295-
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
296-
driver
297-
.executeQuery('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)
293+
// Since 5.8.0, the driver has offered a way to run a single query transaction with minimal boilerplate.
294+
// The driver.executeQuery() function features the same automatic retries as transaction functions.
295+
//
296+
var executeQueryResultPromise = driver
297+
.executeQuery(
298+
"MATCH (alice:Person {name: $nameParam}) RETURN alice.DOB AS DateOfBirth",
299+
{
300+
nameParam: 'Alice'
301+
},
302+
{
303+
routing: 'READ',
304+
database: 'neo4j'
312305
}
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-
driver
327-
.executeQuery('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())
306+
)
339307
```
340308

341-
#### Consuming Records with Reactive API
309+
### Auto-Commit/Implicit Transaction
342310

343311
```javascript
344-
rxSession
345-
.executeRead(txc =>
346-
txc
347-
.run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {
348-
nameParam: 'Bob'
349-
})
350-
)
351-
.records()
352-
.pipe(
353-
map(record => record.get('name')),
354-
concatWith(rxSession.close())
312+
// This is the most basic and limited form with which to run a Cypher query.
313+
// The driver will not automatically retry implicit transactions.
314+
// This function should only be used when the other driver query interfaces do not fit the purpose.
315+
// Implicit transactions are the only ones that can be used for CALL { …​ } IN TRANSACTIONS queries.
316+
317+
var implicitTxResultPromise = session
318+
.run(
319+
"CALL { …​ } IN TRANSACTIONS",
320+
{
321+
param1: 'param'
322+
},
323+
{
324+
database: 'neo4j'
325+
}
355326
)
356-
.subscribe({
357-
next: data => console.log(data),
358-
complete: () => console.log('completed'),
359-
error: err => console.log(err)
360-
})
361327
```
362328

363329
### Explicit Transactions
@@ -437,6 +403,79 @@ rxSession
437403
})
438404
```
439405

406+
### Consuming Records
407+
408+
#### Consuming Records with Streaming API
409+
410+
```javascript
411+
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
412+
driver
413+
.executeQuery('MERGE (alice:Person {name : $nameParam}) RETURN alice.name AS name', {
414+
nameParam: 'Alice'
415+
})
416+
.subscribe({
417+
onKeys: keys => {
418+
console.log(keys)
419+
},
420+
onNext: record => {
421+
console.log(record.get('name'))
422+
},
423+
onCompleted: () => {
424+
session.close() // returns a Promise
425+
},
426+
onError: error => {
427+
console.log(error)
428+
}
429+
})
430+
```
431+
432+
Subscriber API allows following combinations of `onKeys`, `onNext`, `onCompleted` and `onError` callback invocations:
433+
434+
- zero or one `onKeys`,
435+
- zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked in this case
436+
- 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.
437+
438+
#### Consuming Records with Promise API
439+
440+
```javascript
441+
// the Promise way, where the complete result is collected before we act on it:
442+
driver
443+
.executeQuery('MERGE (james:Person {name : $nameParam}) RETURN james.name AS name', {
444+
nameParam: 'James'
445+
})
446+
.then(result => {
447+
result.records.forEach(record => {
448+
console.log(record.get('name'))
449+
})
450+
})
451+
.catch(error => {
452+
console.log(error)
453+
})
454+
.then(() => session.close())
455+
```
456+
457+
#### Consuming Records with Reactive API
458+
459+
```javascript
460+
rxSession
461+
.executeRead(txc =>
462+
txc
463+
.run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {
464+
nameParam: 'Bob'
465+
})
466+
)
467+
.records()
468+
.pipe(
469+
map(record => record.get('name')),
470+
concatWith(rxSession.close())
471+
)
472+
.subscribe({
473+
next: data => console.log(data),
474+
complete: () => console.log('completed'),
475+
error: err => console.log(err)
476+
})
477+
```
478+
440479
### Numbers and the Integer type
441480

442481
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)`.

0 commit comments

Comments
 (0)