forked from rorymadden/neoprene
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.json
64 lines (64 loc) · 4.95 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
"name": "neoprene",
"description": "Neo4j wrapper (REST API client) for Node.js",
"version": "1.0.2",
"author": {
"name": "Rory Madden",
"email": "[email protected]"
},
"homepage": "http://rorymadden.github.com/neoprene",
"contributors": [
{
"name": "Rory Madden",
"email": "[email protected]"
}
],
"private": false,
"main": "./lib",
"dependencies": {
"superagent": "0.12.x",
"async": "0.1.x",
"hooks": "0.2.1"
},
"devDependencies": {
"expect.js": "~0.1.2",
"mocha": "~1.3.0",
"assert": "*"
},
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "make test",
"docs": "make docs"
},
"keywords": [
"neo4j",
"graph",
"database",
"driver",
"rest",
"api",
"client"
],
"bugs": {
"url": "http://github.com/rorymadden/neoprene/issues"
},
"licenses": [
{
"type": "Apache License, Version 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
],
"repository": {
"type": "git",
"url": "http://github.com/rorymadden/neoprene.git"
},
"readme": "# Neoprene\n\nNeo4j Object Modelling for Node.js\n\nAcknowledgements:\nThis library is based heavily on the mongoose ORM for mongodb. The neo4j REST API was based on the 'node-neo4j' library.\n\n\n## Installation\n\n npm install neoprene\n\n\n## Usage\n\n```js\nvar neoprene = require('neoprene');\nneoprene.connect('http://localhost:7474');\n```\n\nIf you have used mongoose before there are a few things which need to be handled differently. \n\nFirstly Node has two types of objects: Nodes and Relationships. When specifying a new model you need to identify the model type that you want.\n\n***Note***\nSpecifying indexes in Schemas does not work at present. Please see the issues section - pull requests welcome.\n\n```js\nvar TestNodeSchema = new Schema({\n name: { type:String }\n})\nvar TestNode = neoprene.model('node', 'TestNode', TestNodeSchema)\n\nvar node = new TestNode({name: 'test'})\nnode.save(function(err, node){\n ....\n});\n\nvar node2 = new TestNode({name: 'test2'})\nnode2.save(function(err, node){\n ....\n});\n```\n\nInstead of creating joins between tables you need to create relationships. Relationships need a direction. You can create relationships To or From another node.\n\n```js\nvar FollowsSchema = new Schema({\n start: { type:Date, required: true },\n end: { type:Date, required: true }\n});\nneoprene.model('relationship', 'follows', FollowsSchema);\n\nvar startDate = new Date(2013, 0, 16);\nvar endDate = new Date(2014, 0, 16);\n\nnode.createRelationshipTo(node2, 'follows', {start: startDate, end: endDate}, function(err, rel){\n ...\n});\n```\n\nYou often want to create a relationship when you are creating a node. It wouldn't be good to make you hit the database twice. When saving a node for the first time you can add in a relationship as well. \n\n```js\nvar node1 = new TestNode({name: 'no relationship'});\nvar node2 = new TestNode({name: 'should link to 1'});\n\nnode1.save(function(err, savedNode){\n // you need to supply the linked node by either id or email\n // you need to supply a type and a direction as well\n var rel = {id: savedNode.id, type: 'Friend', direction: 'to' };\n node2.save(rel, function(err, savedNode2){\n // other code\n })\n})\n})\n```\n\n\nTo query / navigate around the graph you start with a single node. You can index nodes to enable quick lookup at a later time.\n\n```js\nnode.index('Test', 'name', this.name, function(err){\n ...\n});\n\nvar myFetchedNode;\nneoprene.getIndexedNode('Test', 'name', 'test', function(err, node){\n myFetchedNode = node;\n})\n```\n\nOnce you have a node you can traverse the graph. You can get Relationships or Nodes. \nTo get relationships you can choose incoming, outgoing or all relationships. In addition you must specify a type or array of relationship types. \nWhen getting nodes you can use the adjacentNodes helper or the more complete traverse function. \n\n```js\nnode.getAllRelationships('follows', function(err, rels){\n ...\n})\n\nnode.adjacentNodes('follows', 2, function(err, nodes){\n ...\n})\n```\n\nThe final way to query the graph is to run a Cypher query against the graph.\n\n```js\nvar query = [\n 'START user=node({userId})',\n 'MATCH (user) -[:likes]-> (other)',\n 'RETURN other'\n].join('\\n');\n\nvar params = {\n userId: currentUser.id\n};\n\nneoprene.query(query, params, function (err, results) {\n if (err) throw err;\n var likes = results.map(function (result) {\n return result['other'];\n });\n // ...\n});\n```\n\nIf you're new to Neo4j, read the [Getting Started][neo4j-getting-started] page.\n\n\n[neo4j]: http://neo4j.org/\n[neo4j-rest-api]: http://docs.neo4j.org/chunked/stable/rest-api.html\n\n[neo4j-getting-started]: http://wiki.neo4j.org/content/Getting_Started_With_Neo4j_Server\n",
"readmeFilename": "README.md",
"_id": "[email protected]",
"dist": {
"shasum": "9a3e7f0f402cc0fe5862fe8155d149504e094511"
},
"_from": "[email protected]"
}