Socket
Socket
Sign inDemoInstall

neo4j-driver

Package Overview
Dependencies
Maintainers
2
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

neo4j-driver - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0-alpha.0

.idea/.name

66

package.json
{
"name": "neo4j-driver",
"version": "0.0.2",
"description": "Javascript driver for Neo4j 2.2+ with Cypher and Transactions as first class citizens.",
"main": "index.js",
"scripts": {
"test": "lab -fL -t 100 -m 10000",
"test-cov": "lab -fL -r html -o coverage.html",
"test-coveralls": "lab -fL -t 100 -m 10000 -r lcov | coveralls",
"test-travis": "npm run test && npm run test-coveralls"
},
"version": "1.0.0-alpha.0",
"description": "Connect to Neo4j 3.0.0 and up from JavaScript",
"author": "Neo Technology Inc.",
"license": "Apache License 2.0",
"repository": {
"type": "git",
"url": "https://github.com/ldesplat/neo4j-driver"
"url": "git://github.com/neo4j/neo4j-javascript-driver.git"
},
"keywords": [
"neo4j",
"driver",
"cypher",
"transaction"
],
"author": "Lois Desplat <lois.desplat@gmail.com> (http://www.loisdesplat.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/ldesplat/neo4j-driver/issues"
"scripts": {
"test": "gulp test",
"build": "gulp all",
"start-neo4j": "gulp start-neo4j",
"stop-neo4j": "gulp stop-neo4j",
"prepublish": "npm run build",
"docs": "node_modules/.bin/esdoc -c esdoc.json"
},
"homepage": "https://github.com/ldesplat/neo4j-driver",
"dependencies": {
"hoek": "^2.12.0",
"wreck": "^5.4.0"
},
"main": "lib/neo4j.js",
"devDependencies": {
"code": "^1.4.0",
"coveralls": "^2.11.2",
"lab": "^5.5.1"
"babel": "^5.8.23",
"babelify": "^6.3.0",
"browserify": "^11.0.0",
"esdoc": "^0.4.0",
"glob": "^5.0.14",
"gulp": "^3.9.0",
"gulp-babel": "^5.2.1",
"gulp-batch": "^1.0.5",
"gulp-concat": "^2.6.0",
"gulp-cucumber": "^0.0.12",
"gulp-download": "^0.0.1",
"gulp-if": "^1.2.5",
"gulp-jasmine": "^2.1.0",
"gulp-jasmine-browser": "^0.2.3",
"gulp-shell": "^0.4.3",
"gulp-uglify": "^1.4.2",
"gulp-util": "^3.0.6",
"gulp-watch": "^4.3.5",
"jasmine-reporters": "^2.0.7",
"phantomjs2-ext": "^0.1.0",
"run-sequence": "^1.1.4",
"through2": "~2.0.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"gulp-decompress": "^1.2.0"
}
}

@@ -1,165 +0,107 @@

# Neo4j-driver [![Build Status](https://travis-ci.org/ldesplat/neo4j-driver.svg?branch=master)](https://travis-ci.org/ldesplat/neo4j-driver) [![Coverage Status](https://coveralls.io/repos/ldesplat/neo4j-driver/badge.svg?branch=master)](https://coveralls.io/r/ldesplat/neo4j-driver?branch=master) [![Dependency Status](https://david-dm.org/ldesplat/neo4j-driver.svg?style=flat)](https://david-dm.org/ldesplat/neo4j-driver)
This driver supports Cypher and Transactions as first class citizens. It is meant to be used for heavy writes and heavy queries. For that reason, it tries to do the least possible while still trying to provide optional utilities to make our jobs as developers easier.
# Neo4j Driver for Javascript
## Contributions
If you have <b>any questions</b> or issues, please raise them in the issue tracker on github.
An alpha-level database driver for a new Neo4j remoting protocol.
Contributions are very welcome. They must come with 100% test coverage and documentation, if appropriate, before being merged. They can be submitted beforehand if you need any help.
Note: This is in active development, the API is not stable. Please try it out and give us feedback, but expect things to break in the medium term!
## Roadmap
## Include module in Node.js application
- Utilities to deal with results array, errors, ...
- SSL Support
- Investigate potential issues if Neo4j is behind a reverse proxy (ie. changing hostname/ports during discovery)
- Provide streaming support to transaction endpoint responses
- Allow to change resultDataContents -> Should be part of options object
- Provide logging hooks
- Provide events such as (Transaction about to expire soon, Transaction expired, Log Happened)
- Expose Expiry time in transact object
- Investigate running in browser
## API
For more examples, you can check out the test folder.
> Note
>
> By default the connections to Neo4j are long lived. If you use Node 0.10, then this might not be the case and you will most likely get performance issues as you scale the amount of requests. This is not a problem with Node 0.12+ or iojs.
### Client
#### Client([options,] callback)
This is the constructor for our client. You can instantiate multiple versions of it with the same or different endpoints.
The options it can take are the following:
- `url` The url where the Neo4j database is listening
- `timeout` The timeout in ms for any HTTP request or response dealing with Neo4j
- `credentials` An object which includes `username` and `password` for authorization with Neo4j
The callback has the following properties:
- `error` If any errors occurred you will get an Error object
- `client`
- Null if any errors occurred
- The object you will use to interact with this library
```javascript
var Neo4j = require('neo4j-driver');
Neo4j.Client({ url: 'http://localhost:7474/db/data/' }, function (err, client) {
// client.cypher
// client.transact
})
var neo4j = require('lib/neo4j');
```
> Note
>
> The client does not give you options to change your password or do maintenance tasks. It is only meant for using during an application that does lots of queries and writes. If there are any issues, this first call to the constructor will fail.
## Include in web browser
A global object `neo4j` will be available.
#### cypher(query, [params,] callback)
This is a convenience method to run one cypher statement. In the background this actually invokes a transaction that does commit right away.
- `query` A Cypher statement represented as a string
- `params` Optional params object in case you used parameters in your cypher query
- `callback` When the query is done, returns a potential error object and results array
- `error`
- Null if there are no issues
- An object (could be Error or not) if something went wrong during transport
- Neo4j error array if errors were returned from Neo4j about your statements
- `results`
- Null if there were errors
- An array returned from Neo4j containing the results of the statements
```javascript
client.cypher('MATCH (n:Person) RETURN n', function (err, results) {
});
```html
<script src="lib/browser/neo4j-web.min.js"></script>
```
#### transact()
Returns a new Transaction object. See below for its API.
```javascript
var transact = client.transact();
```
## Usage examples (for both Node.js and browser environments)
### Transaction
Create a transaction object by using `client.transact()`. If you want to use Transaction by itself (not recomended), then you can look at `test/transaction.js` and of course the constructor in `lib/transaction.js`.
#### transact(statements, [options,] callback)
This method allows you to run statements in the current transaction. See [Transaction Cypher HTTP endpoint](http://neo4j.com/docs/stable/rest-api-transactional.html) documentation for more details.
The statements are of this format:
```javascript
var statements = [
{
"statement": "CREATE (n {props}) RETURN n",
"parameters": {
"props": {
"name": "My Node"
}
}
},
{
"statement": "MATCH (n) RETURN n"
}
var statement = ['MERGE (alice:Person {name:{name_a},age:{age_a}})',
'MERGE (bob:Person {name:{name_b},age:{age_b}})',
'CREATE UNIQUE (alice)-[alice_knows_bob:KNOWS]->(bob)',
'RETURN alice, bob, alice_knows_bob'
];
```
The options object:
- `commit` true if you want to commit. False by default
var params = {
name_a: 'Alice',
age_a: 33,
name_b: 'Bob',
age_b: 44
};
The callback has the following properties:
- `error`
- Null if no errors
- An object if anything went wrong that is not related to Neo4j
- An array of errors returned by Neo4j
- `results`
- Array of results returned by Neo4j
```javascript
var Neo4j = require('neo4j-driver');
Neo4j.Client({}, function (err, client) {
// Create a Session object to contain all Cypher activity.
var driver = neo4j.driver("bolt://localhost");
var session = driver.session();
if (err) {
console.log(err);
process.exit(1);
// Run a Cypher statement within an implicit transaction
// The streaming way:
session.run(statement.join(' '), params).subscribe({
onNext: function(record) {
// On receipt of RECORD
for(var i in record) {
console.log(i, ': ', record[i]);
}
}, onCompleted: function() {
session.close();
}, onError: function(error) {
console.log(error);
}
});
var transaction = client.transact();
transaction.transact(statements, function (error, results) {
// look at your results
transaction.rollback(function (err) {
// rolled the transaction back
};
// or
// the Promise way, where the complete response is collected:
session.run(statement.join(' '), params)
.then(function(records){
records.forEach(function(record) {
for(var i in record) {
console.log(i, ': ', record[i]);
}
});
session.close();
})
.catch(function(error) {
console.log(error);
});
});
```
#### commit(statements, options, callback)
This is a helper method. It just calls the transact method with options `{ commit: true }`. See Transaction.transact for details.
## Building
#### rollback(callback)
Rolls back the current transaction. You cannot use the transact object after that. You can try, but Neo4j will return errors.
npm install
npm build
The callback has the following properties:
- `error` If error is null, then the rollback was successful
This produces browser-compatible standalone files under `lib/browser` and a Node.js module version under `lib/`.
See files under `examples/` on how to use.
```javascript
transaction.rollback(function (error) {
## Testing
});
```
./runTests.sh
#### extend(callback)
Sends a keep alive to Neo4j to extend the time of the transaction.
This runs the test suite against a fresh download of Neo4j.
Or `npm test` if you already have a running version of a compatible Neo4j server.
The callback has the following properties:
- `error` If error is null, then the extend was successful
### Testing on windows
Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable `Path`.
To run the same test suite, run `.\runTest.ps1` instead in powershell with admin right.
The admin right is required to start/stop Neo4j properly as a system service.
While there is no need to grab admin right if you are running tests against an existing Neo4j server using `npm test`.
```javascript
transaction.extend(function (error) {
## A note on numbers and the Integer type
For this driver to fully map to the Neo4j type system handling of 64-bits Integers is needed.
Javascript can saftely represent numbers between `-(2`<sup>`53`</sup>` - 1)` and `(2`<sup>`53`</sup>` - 1)`.
Therefore, an Integer type is introduced.
});
```
### Write integers
Number written directly e.g. `session.run("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.
E.g. `session.run("CREATE (n:Node {age: {age}})", {age: neo4j.int(22)})`.
### Read integers
To get the value of a from Neo4j received integer, the safeast way would be to use the `.toString()` method on
an Integer object.
E.g. `console.log(result.age.toString())`.
To check if a variable is of the Integer type, the method `neo4j.isInt(variable)` can be used.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc