Skip to content

Commit

Permalink
Merge branch 'docs' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesfer committed Mar 6, 2018
2 parents 0418ffc + 3570c26 commit ecd54d3
Show file tree
Hide file tree
Showing 32 changed files with 23,825 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
npm_debug.log
yarn-error.log
.idea/
.nyc_output/
coverage/
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 James Ferguson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
865 changes: 865 additions & 0 deletions docs/assets/css/main.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/assets/css/main.css.map

Large diffs are not rendered by default.

Binary file added docs/assets/images/icons.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/icons@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/widgets.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/widgets@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/assets/js/main.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/assets/js/search.js

Large diffs are not rendered by default.

2,060 changes: 2,060 additions & 0 deletions docs/classes/builder.html

Large diffs are not rendered by default.

2,305 changes: 2,305 additions & 0 deletions docs/classes/connection.html

Large diffs are not rendered by default.

2,370 changes: 2,370 additions & 0 deletions docs/classes/query.html

Large diffs are not rendered by default.

1,196 changes: 1,196 additions & 0 deletions docs/classes/whereand.html

Large diffs are not rendered by default.

1,196 changes: 1,196 additions & 0 deletions docs/classes/wherenot.html

Large diffs are not rendered by default.

1,169 changes: 1,169 additions & 0 deletions docs/classes/whereop.html

Large diffs are not rendered by default.

1,196 changes: 1,196 additions & 0 deletions docs/classes/whereor.html

Large diffs are not rendered by default.

1,196 changes: 1,196 additions & 0 deletions docs/classes/wherexor.html

Large diffs are not rendered by default.

2,680 changes: 2,680 additions & 0 deletions docs/globals.html

Large diffs are not rendered by default.

2,681 changes: 2,681 additions & 0 deletions docs/index.html

Large diffs are not rendered by default.

1,150 changes: 1,150 additions & 0 deletions docs/interfaces/credentials.html

Large diffs are not rendered by default.

1,164 changes: 1,164 additions & 0 deletions docs/interfaces/driver.html

Large diffs are not rendered by default.

1,173 changes: 1,173 additions & 0 deletions docs/interfaces/session.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build:prod": "webpack --progress --env.production",
"test": "nyc --reporter=text --reporter=html mocha src/*.spec.ts src/**/*.spec.ts",
"release": "./scripts/release.sh",
"docs": "typedoc src/builder.ts src/query.ts src/connection.ts src/clauses/index.ts src/clauses/where-comparators.ts src/clauses/where-operators.ts --mode file --theme minimal --out ./docs --excludeExternals --excludeProtected --excludePrivate --ignoreCompilerErrors",
"ci:test": "nyc --reporter=lcov --reporter=text mocha src/*.spec.ts src/**/*.spec.ts",
"ci:report": "./node_modules/.bin/nyc report --reporter=text-lcov | coveralls"
},
Expand Down Expand Up @@ -68,6 +69,7 @@
"source-map-support": "^0.5.0",
"ts-loader": "^3.1.1",
"ts-node": "^4.1.0",
"typedoc": "^0.10.0",
"typescript": "^2.5.3",
"uglifyjs-webpack-plugin": "^0.4.6",
"webpack": "^3.6.0",
Expand Down
99 changes: 79 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
A flexible and intuitive query builder for Neo4j and Cypher.
Write queries in Javascript just as you would write them in Cypher.

let results = await db.matchNode('user', 'User', { email: 'email@email.com' })
let results = await db.matchNode('user', 'User', { active: true })
.where({ 'user.age': greaterThan(18) })
.with('user')
.create([
cypher.node('user', ''),
cypher.relation('out', '', 'HasPost'),
cypher.node('post', 'Post', { body: 'Hello!' })
cypher.relation('out', '', 'HasVehicle'),
cypher.node('vehicle', 'Vehicle', { colour: 'red' })
])
.ret(['user', 'post'])
.ret(['user', 'vehicle'])
.run();

// Results:
Expand All @@ -22,42 +23,69 @@ Write queries in Javascript just as you would write them in Cypher.
// labels: [ 'User' ],
// properites: { ... },
// },
// post: {
// vehicle: {
// identity: 4321,
// labels: [ 'Post' ],
// labels: [ 'Vehicle' ],
// properties: { ... },
// },
// }]

This package is currently in development and many things are likely to be
undocumented or to change without warning. However, any feedback is welcome.
## Quick start

## Usage
### Installing

### Creating a connection
npm install --save cypher-query-builder
or

yarn install cypher-query-builder

### Importing
CommonJS/Node

const cypher = require('cypher-query-builder');
// cypher.Connection
// cypher.greaterThan
// ....

ES6

import { Connection, greaterThan } from 'cypher-query-builder';

### Connecting

const cypher = require('cypher-query-builder');

// Make sure to include the protocol in the hostname
let db = new cypher.Connection('bolt://localhost', {
username: 'root',
password: 'password',
});

Cypher query builder uses the official Neo4j Nodejs driver over the bolt
protocol in the background so you can pass any values into connection that
are accepted by that driver.

The Connection class implements the query builder interface.
### Querying

ES5

db.matchNode('projects', 'Project')
.ret('projects')
.run()
.then(function (results) {
// Do something with results
});

ES6

const results = await db.matchNode('projects', 'Project')
.ret('projects')
.run();

`run` will execute the query and return a promise. The results are in the
_standardish_ Neo4j form of:
_standardish_ Neo4j form an array of records:

// An array of all rows
[
// If you return more than one thing in your RETURN clause
// there will be multiple properties of each row, like in
// the first example. In this case there is only one.
{
projects: {
// Internal Neo4j node id, don't rely on this to stay constant.
Expand All @@ -70,21 +98,52 @@ _standardish_ Neo4j form of:
// Note that Neo4j numbers will automatically be converted to
// Javascript numbers. This may cause issues because Neo4j can
// store larger numbers than can be represented in Javascript.
// This behaviour is currently in development and may change
// This behaviour is currently in consideration and may change
// in the future.
properties: { name: 'Project 1' },
},
},
...
]

I've found that the best way to extract the data you want is with lodash.
### Processing

To extract the results, you can use ES5 array methods or a library like lodash:

// Get all the project nodes (including their id, labels and properties).
let projects = map(results, 'projects');
let projects = results.map(row => row.projects);

// Get just the properties of the nodes
let projectProps = map(results, row => row.projects.properties);
let projectProps = results.map(row => row.projects.properties);

## Documentation

For more details on creating a connection, see the
[Connection](http://jamesfer.me/cypher-query-builder/classes/connection.html) class.

For more details on clauses and running queries, see the
[Query](http://jamesfer.me/cypher-query-builder/classes/query.html) class.

## License

MIT License

Copyright (c) 2018 James Ferguson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0 comments on commit ecd54d3

Please sign in to comment.