Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graphaware/node-neo4j-bolt-adapter
An adapter for the official neo4j-javascript-driver, allowing it to be used as a drop-in replacement for the node-neo4j community driver.
https://github.com/graphaware/node-neo4j-bolt-adapter
adapter community javascript neo4j official
Last synced: 2 months ago
JSON representation
An adapter for the official neo4j-javascript-driver, allowing it to be used as a drop-in replacement for the node-neo4j community driver.
- Host: GitHub
- URL: https://github.com/graphaware/node-neo4j-bolt-adapter
- Owner: graphaware
- Created: 2017-07-11T03:27:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-10T19:24:23.000Z (over 5 years ago)
- Last Synced: 2024-09-27T21:41:46.511Z (3 months ago)
- Topics: adapter, community, javascript, neo4j, official
- Language: JavaScript
- Size: 18.6 KB
- Stars: 5
- Watchers: 6
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
An adapter to allow the official Neo4j bolt driver
to be used as a drop in replacement for the node-neo4j community
driver.# Usage
Given the node-neo4j community driver declared as follows:
```javascript 1.6
const Promise = require('bluebird')
const neo4j = require('node-neo4j')
const dev = require('./dev')
const db = Promise.promisifyAll(new neo4j(
`http://${process.env.DB_USER}:${process.env.DB_PW}@${process.env.DB_HOST}:7474`))module.exports = db;
```
And used like:
```javascript 1.6const db = require('db')
db.cypherQueryAsync(`MATCH (u:User) WHERE u.applicationToken = {applicationToken} RETURN U`,
{applicationToken: 1234})
.then(result => {
//result.columns describes format
//When a single record is return result.data contains an object, otherwise an array of objects.
});
```We can define an adapter for the official bolt driver:
```javascript 1.6
const neo = require('neo4j-driver').v1;
const authToken = neo.auth.basic(userName, password);
const db = new BoltAdapter(neo.driver(`bolt://localhost`, authToken));
```And use it as an API compatible drop-in replacement:
## For a read transaction:
```javascript 1.6
db.cypherQueryAsync(`MATCH (u:User) WHERE u.applicationToken = {applicationToken} RETURN U`,
{applicationToken: 1234})
.then(result => {
//result.columns describes format
//When a single record is return result.data contains an object, otherwise an array of objects.
});
```A session will be opened and a transaction initiated, with auto commit or rollback if an error is thrown. On completion the session will be closed.
## For a write transaction
```javascript 1.6
//For write transactions
db.writeQueryAsync(`CREATE (u:User {name: 'Fred'}) return u`)
.then(result => {
//result.columns describes format
//When a single record is return result.data contains an object, otherwise an array of objects.
});```
Similar to a read transaction, a session will be opened and a transaction initiated. The session is closed on completion.
## Closing
```javascript 1.6
//We can keep a reference, or alternatively, to close the underlying bolt driver
db.close()
```## Note
Currently access mode and read/write transaction functions in the official driver are mostly hints. They are not yet translated to access mode on the server - only used by routing driver to decide where to point the request. Until that behavior changes, it is possible to write in a read transaction.