Skip to content

Add version to API #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2015
Merged
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
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Note: This is in active development, the API is not stable. Please try it out an
## Include module in Node.js application

```javascript
var neo4j = require('neo4j');
var neo4j = require('neo4j').v1;
```

## Include in web browser
Expand Down Expand Up @@ -71,37 +71,37 @@ session.run(statement.join(' '), params)

## Building

npm install
npm install
npm build

This produces browser-compatible standalone files under `lib/browser` and a Node.js module version under `lib/`.
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.

## Testing

./runTests.sh

This runs the test suite against a fresh download of Neo4j.
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.

### 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.
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`.

## 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.
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.
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 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.
12 changes: 7 additions & 5 deletions src/neo4j.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
* limitations under the License.
*/

import {int, isInt} from './integer';
import Driver from './driver';
import {int, isInt} from './v1/integer';
import Driver from './v1/driver';

let USER_AGENT = "neo4j-javascript/0.0";

export default {
driver: (url) => new Driver( url, USER_AGENT ),
int: int,
isInt: isInt
v1: {
driver: (url) => new Driver(url, USER_AGENT),
int: int,
isInt: isInt
}
}
2 changes: 1 addition & 1 deletion src/driver.js → src/v1/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Driver {
let _driver = this;
let _session = new Session( conn, () => {
// On close of session, remove it from the list of open sessions
delete _driver._openSessions[sessionId];
delete _driver._openSessions[sessionId];
});

this._openSessions[sessionId] = _session;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/result-summary.js → src/v1/result-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

import neo4j from './neo4j';
import neo4j from './../neo4j';

/**
* A ResultSummary instance contains structured metadata for a {Result}.
Expand Down Expand Up @@ -126,7 +126,7 @@ class StatementStatistics {
constraintsRemoved: 0
}
Object.keys(statistics).forEach((index) => {
let val = neo4j.isInt(statistics[index]) ? statistics[index].toInt() : statistics[index];
let val = neo4j.v1.isInt(statistics[index]) ? statistics[index].toInt() : statistics[index];
//To camelCase
this._stats[index.replace(/(\-\w)/g, (m) => m[1].toUpperCase())] = val;
});
Expand Down
2 changes: 1 addition & 1 deletion src/result.js → src/v1/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {ResultSummary} from './result-summary';

// Ensure Promise is available
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions test/driver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var neo4j = require("../lib/neo4j");

var neo4j = require("../lib/neo4j").v1;

describe('driver', function() {
it('should expose sessions', function() {
Expand All @@ -31,4 +31,4 @@ describe('driver', function() {
expect( session ).not.toBeNull();
driver.close();
});
});
});
16 changes: 8 additions & 8 deletions test/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var neo4j = require("../lib/neo4j");

var neo4j = require("../lib/neo4j").v1;
var StatementType = require("../lib/result-summary").statementType;

describe('session', function() {
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('session', function() {
done();
}
}

// When & Then
driver.session().run( "RETURN 1.0 AS a").subscribe(new myObserver());
});
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('session', function() {
var driver = neo4j.driver("bolt://localhost");
// When & Then
driver.session().run( "RETURN 1.0 AS a")
.then(
.then(
function( records ) {
expect( records.length ).toBe( 1 );
expect( records[0]['a'] ).toBe( 1 );
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('session', function() {
expect(sum.updateStatistics.containsUpdates()).toBe(true);
expect(sum.updateStatistics.nodesCreated()).toBe(1);
expect(sum.statementType).toBe(StatementType.READ_WRITE);
driver.close();
driver.close();
done();
});
});
Expand All @@ -162,7 +162,7 @@ describe('session', function() {
expect(sum.plan.arguments.runtime).toBe('INTERPRETED');
expect(sum.plan.identifiers[0]).toBe('n');
expect(sum.plan.children[0].operatorType).toBe('CreateNode');
driver.close();
driver.close();
done();
});
});
Expand All @@ -184,7 +184,7 @@ describe('session', function() {
expect(sum.profile.children[0].operatorType).toBe('Filter');
expect(sum.profile.rows).toBeGreaterThan(0);
//expect(sum.profile.dbHits).toBeGreaterThan(0);
driver.close();
driver.close();
done();
});
});
Expand All @@ -201,7 +201,7 @@ describe('session', function() {
expect(sum.notifications[0].code).toBe("Neo.ClientNotification.Statement.CartesianProduct");
expect(sum.notifications[0].title).toBe("This query builds a cartesian product between disconnected patterns.");
expect(sum.notifications[0].position.column).toBeGreaterThan(0);
driver.close();
driver.close();
done();
});
});
Expand Down
26 changes: 13 additions & 13 deletions test/types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var neo4j = require("../lib/neo4j");

var neo4j = require("../lib/neo4j").v1;

describe('floating point values', function() {
it('should support float 1.0 ', testVal( 1 ) );
it('should support float 0.0 ', testVal( 0.0 ) );
it('should support pretty big float ', testVal( 3.4028235e+38 ) ); // Max 32-bit
it('should support pretty big float ', testVal( 3.4028235e+38 ) ); // Max 32-bit
it('should support really big float ', testVal( 1.7976931348623157e+308 ) ); // Max 64-bit
it('should support pretty small float ', testVal( 1.4e-45 ) ); // Min 32-bit
it('should support really small float ', testVal( 4.9e-324 ) ); // Min 64-bit
Expand Down Expand Up @@ -66,15 +66,15 @@ describe('node values', function() {
// Given
var driver = neo4j.driver("bolt://localhost");
var session = driver.session();

// When
session.run("CREATE (n:User {name:'Lisa'}) RETURN n, id(n)").then(function(rs) {
var node = rs[0]['n'];

expect( node.properties ).toEqual( { name:"Lisa" } );
expect( node.labels ).toEqual( ["User"] );
// expect( node.identity ).toEqual( rs[0]['id(n)'] ); // TODO
driver.close();
driver.close();
done();

});
Expand All @@ -86,15 +86,15 @@ describe('relationship values', function() {
// Given
var driver = neo4j.driver("bolt://localhost");
var session = driver.session();

// When
session.run("CREATE ()-[r:User {name:'Lisa'}]->() RETURN r, id(r)").then(function(rs) {
var rel = rs[0]['r'];

expect( rel.properties ).toEqual( { name:"Lisa" } );
expect( rel.type ).toEqual( "User" );
// expect( rel.identity ).toEqual( rs[0]['id(r)'] ); // TODO
driver.close();
driver.close();
done();

});
Expand All @@ -106,7 +106,7 @@ describe('path values', function() {
// Given
var driver = neo4j.driver("bolt://localhost");
var session = driver.session();

// When
session.run("CREATE p=(:User { name:'Lisa' })<-[r:KNOWS {since:1234.0}]-() RETURN p")
.then(function(rs) {
Expand All @@ -125,22 +125,22 @@ describe('path values', function() {
// Which is the inverse of the relationship itself!
expect( segment.relationship.properties ).toEqual( { since: 1234 } );
};
driver.close();
driver.close();
done();
});
});
});

function testVal( val ) {
function testVal( val ) {
return function( done ) {
var driver = neo4j.driver("bolt://localhost");
var session = driver.session();

session.run("RETURN {val} as v", {val: val})
.then( function( records ) {
expect( records[0]['v'] ).toEqual( val );
.then( function( records ) {
expect( records[0]['v'] ).toEqual( val );
driver.close();
done();
});
}
}
}