Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 121 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@ Stable channel:
npm install neo4j-driver
```

Pre-release channel:

```shell
npm install neo4j-driver@next
```

Please note that `@next` only points to pre-releases that are not suitable for production use.
To get the latest stable release omit `@next` part altogether or use `@latest` instead.

```javascript
// If you are using CommonJS
var neo4j = require('neo4j-driver')
// Alternatively, if you are using ES6
import neo4j from 'neo4j-driver'
```

Driver instance should be closed when Node.js application exits:
Driver instance should be closed when the application exits:

```javascript
driver.close() // returns a Promise
Expand Down Expand Up @@ -225,7 +219,7 @@ readTxResultPromise
.catch(error => {
console.log(error)
})
.then(() => session.close())
.finally(() => session.close())
```

#### Reading with Reactive Session
Expand Down Expand Up @@ -269,7 +263,7 @@ writeTxResultPromise
.catch(error => {
console.log(error)
})
.then(() => session.close())
.finally(() => session.close())
```

#### Writing with Reactive Session
Expand All @@ -289,74 +283,62 @@ rxSession
})
```

### Consuming Records

#### Consuming Records with Streaming API
### ExecuteQuery Function

```javascript
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
session
.run('MERGE (alice:Person {name : $nameParam}) RETURN alice.name AS name', {
nameParam: 'Alice'
})
.subscribe({
onKeys: keys => {
console.log(keys)
},
onNext: record => {
console.log(record.get('name'))
},
onCompleted: () => {
session.close() // returns a Promise
},
onError: error => {
console.log(error)
// Since 5.8.0, the driver has offered a way to run a single query transaction with minimal boilerplate.
// The driver.executeQuery() function features the same automatic retries as transaction functions.
//
var executeQueryResultPromise = driver
.executeQuery(
"MATCH (alice:Person {name: $nameParam}) RETURN alice.DOB AS DateOfBirth",
{
nameParam: 'Alice'
},
{
routing: 'READ',
database: 'neo4j'
}
})
```

Subscriber API allows following combinations of `onKeys`, `onNext`, `onCompleted` and `onError` callback invocations:

- zero or one `onKeys`,
- zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked in this case
- 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.

#### Consuming Records with Promise API
)

```javascript
// the Promise way, where the complete result is collected before we act on it:
session
.run('MERGE (james:Person {name : $nameParam}) RETURN james.name AS name', {
nameParam: 'James'
})
// returned Promise can be later consumed like this:
executeQueryResultPromise
.then(result => {
result.records.forEach(record => {
console.log(record.get('name'))
})
console.log(result.records)
})
.catch(error => {
console.log(error)
})
.then(() => session.close())
```

#### Consuming Records with Reactive API
### Auto-Commit/Implicit Transaction

```javascript
rxSession
.run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {
nameParam: 'Bob'
})
.records()
.pipe(
map(record => record.get('name')),
concatWith(rxSession.close())
// This is the most basic and limited form with which to run a Cypher query.
// The driver will not automatically retry implicit transactions.
// This function should only be used when the other driver query interfaces do not fit the purpose.
// Implicit transactions are the only ones that can be used for CALL { …​ } IN TRANSACTIONS queries.

var implicitTxResultPromise = session
.run(
"CALL { …​ } IN TRANSACTIONS",
{
param1: 'param'
},
{
database: 'neo4j'
}
)
.subscribe({
next: data => console.log(data),
complete: () => console.log('completed'),
error: err => console.log(err)

// returned Promise can be later consumed like this:
implicitTxResultPromise
.then(result => {
console.log(result.records)
})
.catch(error => {
console.log(error)
})
.finally(() => session.close())
```

### Explicit Transactions
Expand Down Expand Up @@ -403,7 +385,7 @@ rxSession
.beginTransaction()
.pipe(
mergeMap(txc =>
concatWith(
concat(
txc
.run(
'MERGE (bob:Person {name: $nameParam}) RETURN bob.name AS name',
Expand Down Expand Up @@ -436,6 +418,76 @@ rxSession
})
```

### Consuming Records

#### Consuming Records with Streaming API

```javascript
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
session
.executeWrite(tx => tx.run('MERGE (alice:Person {name : $nameParam}) RETURN alice.name AS name', {
nameParam: 'Alice'
}).subscribe({
onKeys: keys => {
console.log(keys)
},
onNext: record => {
console.log(record.get('name'))
},
onCompleted: () => {
session.close() // returns a Promise
},
onError: error => {
console.log(error)
}
})
)
```

Subscriber API allows following combinations of `onKeys`, `onNext`, `onCompleted` and `onError` callback invocations:

- zero or one `onKeys`,
- zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked in this case
- 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.

#### Consuming Records with Promise API

```javascript
// the Promise way, where the complete result is collected before we act on it:
driver
.executeQuery('MERGE (james:Person {name : $nameParam}) RETURN james.name AS name', {
nameParam: 'James'
})
.then(result => {
result.records.forEach(record => {
console.log(record.get('name'))
})
})
.catch(error => {
console.log(error)
})
.then(() => driver.close())
```

#### Consuming Records with Reactive API

```javascript
rxSession
.run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {
nameParam: 'Bob'
})
.records()
.pipe(
map(record => record.get('name')),
concatWith(rxSession.close())
)
.subscribe({
next: data => console.log(data),
complete: () => console.log('completed'),
error: err => console.log(err)
})
```

### Numbers and the Integer type

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)`.
Expand All @@ -449,20 +501,20 @@ _**Any javascript number value passed as a parameter will be recognized as `Floa

#### Writing integers

Numbers written directly e.g. `session.run("CREATE (n:Node {age: $age})", {age: 22})` will be of type `Float` in Neo4j.
Numbers written directly e.g. `driver.executeQuery("CREATE (n:Node {age: $age})", {age: 22})` will be of type `Float` in Neo4j.

To write the `age` as an integer the `neo4j.int` method should be used:

```javascript
var neo4j = require('neo4j-driver')

session.run('CREATE (n {age: $myIntParam})', { myIntParam: neo4j.int(22) })
driver.executeQuery('CREATE (n {age: $myIntParam})', { myIntParam: neo4j.int(22) })
```

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`:

```javascript
session.run('CREATE (n {age: $myIntParam})', {
driver.executeQuery('CREATE (n {age: $myIntParam})', {
myIntParam: neo4j.int('9223372036854775807')
})
```
Expand Down
7 changes: 3 additions & 4 deletions packages/bolt-connection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ The build of this package is handled by the root package of this repository.

First it is needed to install the mono-repo dependencies by running `npm ci` in the root of the repository. Then:

* Build all could be performed with
* Building the whole repository can be performed with


```
npm run build
```
* Build only the Core could be performed with
Builind only Core:
* Building only the bolt-connection can be performed with
```
npm run build -- --scope=neo4j-driver-bolt-connection

Expand All @@ -27,7 +26,7 @@ This produces a Node.js module version under `lib/`.

## Testing

The tests could be executed by running `npm test` in this package folder. For development, you can have the build tool rerun the tests each time you change the source code:
The tests can be executed by running `npm test` in this package folder. For development, you can have the build tool rerun the tests each time you change the source code:

```
npm run test::watch
Expand Down
9 changes: 5 additions & 4 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ The build of this package is handled by the root package of this repository.

First it is needed to install the mono-repo dependencies by running `npm ci` in the root of the repository. Then:

* Build all could be performed with
* Building the whole repository can be performed with


```
npm run build
```
* Build only the Core could be performed with
Builind only Core:
* Building only the Core can be performed with


```
npm run build -- --scope=neo4j-driver-core

Expand All @@ -27,7 +28,7 @@ This produces a Node.js module version under `lib/`.

## Testing

The tests could be executed by running `npm test` in this package folder. For development, you can have the build tool rerun the tests each time you change the source code:
The tests can be executed by running `npm test` in this package folder. For development, you can have the build tool rerun the tests each time you change the source code:

```
npm run test::watch
Expand Down
Loading