Skip to content

Commit a10898a

Browse files
committed
Shift to neo4j-driver as name
1 parent 455b2eb commit a10898a

File tree

8 files changed

+104
-67
lines changed

8 files changed

+104
-67
lines changed

README.md

Lines changed: 80 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,75 @@
11
# Neo4j Driver for Javascript
22

3-
An alpha-level database driver for a new Neo4j remoting protocol.
3+
An alpha-level database driver for Neo4j 3.0.0+.
44

55
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!
66

77
## Include module in Node.js application
88

9+
```shell
10+
npm install neo4j-driver
11+
```
12+
913
```javascript
10-
var neo4j = require('neo4j').v1;
14+
var neo4j = require('neo4j-driver/v1');
1115
```
1216

1317
## Include in web browser
14-
A global object `neo4j` will be available.
18+
19+
We build a special browser version of the driver, which supports connecting to Neo4j over WebSockets.
1520

1621
```html
1722
<script src="lib/browser/neo4j-web.min.js"></script>
1823
```
1924

20-
## Usage examples (for both Node.js and browser environments)
25+
This will make a global `neo4j` object available, where you can access the `v1` API at `neo4j.v1`:
2126

2227
```javascript
23-
var statement = ['MERGE (alice:Person {name:{name_a},age:{age_a}})',
24-
'MERGE (bob:Person {name:{name_b},age:{age_b}})',
25-
'CREATE UNIQUE (alice)-[alice_knows_bob:KNOWS]->(bob)',
26-
'RETURN alice, bob, alice_knows_bob'
27-
];
28+
var driver = neo4j.v1.driver("bolt://localhost");
29+
```
2830

29-
var params = {
30-
name_a: 'Alice',
31-
age_a: 33,
32-
name_b: 'Bob',
33-
age_b: 44
34-
};
31+
## Usage examples
3532

33+
```javascript
3634

37-
// Create a Session object to contain all Cypher activity.
35+
// Create a driver instance
3836
var driver = neo4j.driver("bolt://localhost");
37+
38+
// Create a session to run Cypher statements in.
39+
// Note: Always make sure to close sessions when you are done using them!
3940
var session = driver.session();
4041

41-
// Run a Cypher statement within an implicit transaction
42-
// The streaming way:
43-
session.run(statement.join(' '), params).subscribe({
42+
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
43+
session
44+
.run("MATCH (alice {name : {nameParam} }) RETURN alice.age", { nameParam:'Alice' })
45+
.subscribe({
4446
onNext: function(record) {
45-
// On receipt of RECORD
46-
for(var i in record) {
47-
console.log(i, ': ', record[i]);
48-
}
49-
}, onCompleted: function() {
50-
session.close();
51-
}, onError: function(error) {
52-
console.log(error);
47+
console.log(record);
48+
},
49+
onCompleted: function() {
50+
// Completed!
51+
session.close();
52+
},
53+
onError: function(error) {
54+
console.log(error);
5355
}
54-
});
56+
});
5557

5658
// or
57-
// the Promise way, where the complete response is collected:
58-
session.run(statement.join(' '), params)
59-
.then(function(records){
60-
records.forEach(function(record) {
61-
for(var i in record) {
62-
console.log(i, ': ', record[i]);
63-
}
64-
});
65-
session.close();
66-
})
67-
.catch(function(error) {
68-
console.log(error);
59+
// the Promise way, where the complete result is collected before we act on it:
60+
session
61+
.run("MATCH (alice {name : {nameParam} }) RETURN alice.age", { nameParam:'Alice' })
62+
.then(function(records){
63+
records.forEach(function(record) {
64+
console.log(record);
6965
});
66+
67+
// Completed!
68+
session.close();
69+
})
70+
.catch(function(error) {
71+
console.log(error);
72+
});
7073
```
7174

7275
## Building
@@ -85,23 +88,47 @@ This runs the test suite against a fresh download of Neo4j.
8588
Or `npm test` if you already have a running version of a compatible Neo4j server.
8689

8790
### Testing on windows
88-
Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable `Path`.
89-
To run the same test suite, run `.\runTest.ps1` instead in powershell with admin right.
90-
The admin right is required to start/stop Neo4j properly as a system service.
91+
Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable `Path`.
92+
To run the same test suite, run `.\runTest.ps1` instead in powershell with admin right.
93+
The admin right is required to start/stop Neo4j properly as a system service.
9194
While there is no need to grab admin right if you are running tests against an existing Neo4j server using `npm test`.
9295

9396
## A note on numbers and the Integer type
94-
For this driver to fully map to the Neo4j type system handling of 64-bits Integers is needed.
95-
Javascript can saftely represent numbers between `-(2`<sup>`53`</sup>` - 1)` and `(2`<sup>`53`</sup>` - 1)`.
96-
Therefore, an Integer type is introduced.
97+
The Neo4j type system includes 64-bit integer values.
98+
However, Javascript can only safely represent integers between `-(2`<sup>`53`</sup>` - 1)` and `(2`<sup>`53`</sup>` - 1)`.
99+
In order to support the full Neo4j type system, the driver includes an explicit Integer types.
100+
Any time the driver recieves an Integer value from Neo4j, it will be represented with the Integer type by the driver.
97101

98102
### Write integers
99-
Number written directly e.g. `session.run("CREATE (n:Node {age: {age}})", {age: 22})` will be of type `Float` in Neo4j.
100-
To write the `age` as an integer the `neo4j.int` method should be used.
101-
E.g. `session.run("CREATE (n:Node {age: {age}})", {age: neo4j.int(22)})`.
103+
Number written directly e.g. `session.run("CREATE (n:Node {age: {age}})", {age: 22})` will be of type `Float` in Neo4j.
104+
To write the `age` as an integer the `neo4j.int` method should be used:
105+
106+
```javascript
107+
var neo4j = require('neo4j-driver');
108+
109+
session.run("CREATE (n {age: {myIntParam}})", {myIntParam: neo4j.int(22)});
110+
```
111+
112+
To write integers larger than can be represented as JavaScript numbers, use a string argument to `neo4j.int`:
113+
114+
```javascript
115+
session.run("CREATE (n {age: {myIntParam}})", {myIntParam: neo4j.int("9223372036854775807")});
116+
```
102117

103118
### Read integers
104-
To get the value of a from Neo4j received integer, the safeast way would be to use the `.toString()` method on
105-
an Integer object.
106-
E.g. `console.log(result.age.toString())`.
107-
To check if a variable is of the Integer type, the method `neo4j.isInt(variable)` can be used.
119+
Since Integers can be larger than can be represented as JavaScript numbers, it is only safe to convert Integer instances to JavaScript numbers if you know that they will not exceed `(2`<sup>`53`</sup>` - 1)` in size:
120+
121+
```javascript
122+
var aSmallInteger = neo4j.int(123);
123+
var aNumber = aSmallInteger.toNumber();
124+
```
125+
126+
If you will be handling integers larger than that, you can use the Integer instances directly, or convert them to strings:
127+
128+
```javascript
129+
var aLargerInteger = neo4j.int("9223372036854775807");
130+
var integerAsString = aLargerInteger.toString();
131+
```
132+
133+
To help you work with Integers, the Integer class exposes a large set of arithmetic methods.
134+
Refer to the Integer API docs for details.

gulpfile.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ var babelify = require('babelify');
3535
var babel = require('gulp-babel');
3636
var watch = require('gulp-watch');
3737
var batch = require('gulp-batch');
38+
var replace = require('gulp-replace');
39+
var decompress = require('gulp-decompress');
3840
var fs = require("fs");
3941
var runSequence = require('run-sequence');
4042
var path = require('path');
4143
var childProcess = require("child_process");
42-
var decompress = require('gulp-decompress');
44+
var minimist = require('minimist');
4345

4446
gulp.task('default', ["test"]);
4547

@@ -52,7 +54,7 @@ gulp.task('build-browser', function () {
5254
var browserOutput = 'lib/browser';
5355
// Our app bundler
5456
var appBundler = browserify({
55-
entries: ['src/neo4j.js'],
57+
entries: ['src/index.js'],
5658
cache: {},
5759
standalone: 'neo4j',
5860
packageCache: {}
@@ -196,10 +198,16 @@ var runPowershell = function( cmd ) {
196198
child.stdin.end(); //end input
197199
}
198200

199-
// gulp.task('start-neo4j', ['download-neo4j'], shell.task([
200-
// 'chmod +x ' + neo4jHome + '/bin/neo4j',
201-
// neo4jHome + '/bin/neo4j start',
202-
// ]));
201+
gulp.task('set', function() {
202+
// Get the --version arg from command line
203+
var version = minimist(process.argv.slice(2), { string: 'version' }).version;
204+
205+
// Change the version in relevant files
206+
return gulp.src(['package.json'], {base: "./"})
207+
.pipe(replace('0.0.0-dev', version))
208+
.pipe(gulp.dest('./'));
209+
210+
});
203211

204212
gulp.task('start-neo4j', ['download-neo4j'], function() {
205213
if(isWin) {

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "neo4j-driver",
3-
"version": "1.0.0-alpha.1",
3+
"version": "0.0.0-dev",
44
"description": "Connect to Neo4j 3.0.0 and up from JavaScript",
55
"author": "Neo Technology Inc.",
6-
"license": "Apache License 2.0",
6+
"license": "Apache-2.0",
77
"repository": {
88
"type": "git",
99
"url": "git://github.com/neo4j/neo4j-javascript-driver.git"
@@ -27,20 +27,22 @@
2727
"gulp-batch": "^1.0.5",
2828
"gulp-concat": "^2.6.0",
2929
"gulp-cucumber": "^0.0.12",
30+
"gulp-decompress": "^1.2.0",
3031
"gulp-download": "^0.0.1",
3132
"gulp-if": "^1.2.5",
3233
"gulp-jasmine": "^2.1.0",
3334
"gulp-jasmine-browser": "^0.2.3",
35+
"gulp-replace": "^0.5.4",
3436
"gulp-shell": "^0.4.3",
3537
"gulp-uglify": "^1.4.2",
3638
"gulp-util": "^3.0.6",
3739
"gulp-watch": "^4.3.5",
3840
"jasmine-reporters": "^2.0.7",
41+
"minimist": "^1.2.0",
3942
"phantomjs2-ext": "^0.1.0",
4043
"run-sequence": "^1.1.4",
4144
"through2": "~2.0.0",
4245
"vinyl-buffer": "^1.0.0",
43-
"vinyl-source-stream": "^1.1.0",
44-
"gulp-decompress": "^1.2.0"
46+
"vinyl-source-stream": "^1.1.0"
4547
}
4648
}
File renamed without changes.

src/v1/result-summary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
import neo4j from '../neo4j';
20+
import neo4j from '../index';
2121

2222
/**
2323
* A ResultSummary instance contains structured metadata for a {Result}.

test/driver.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
var neo4j = require("../lib/neo4j").v1;
20+
var neo4j = require("../lib/index").v1;
2121

2222
describe('driver', function() {
2323
it('should expose sessions', function() {

test/session.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
var neo4j = require("../lib/neo4j").v1;
20+
var neo4j = require("../lib/index").v1;
2121
var StatementType = require("../lib/v1/result-summary").statementType;
2222

2323
describe('session', function() {

test/types.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
var neo4j = require("../lib/neo4j").v1;
20+
var neo4j = require("../lib/index").v1;
2121

2222
describe('floating point values', function() {
2323
it('should support float 1.0 ', testVal( 1 ) );

0 commit comments

Comments
 (0)