neo4j-core 3.0.0.alpha.10 → 3.0.0.alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +67 -7
- data/lib/neo4j-core/cypher_translator.rb +4 -1
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-server.rb +1 -0
- data/lib/neo4j-server/cypher_session.rb +29 -13
- data/lib/neo4j-server/cypher_transaction.rb +5 -4
- data/lib/neo4j-server/neo4j_server_endpoint.rb +24 -0
- data/lib/neo4j-server/resource.rb +3 -3
- data/lib/neo4j/session.rb +2 -1
- data/neo4j-core.gemspec +3 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fede67cc634151503c9657840ab07e5e5784bff
|
4
|
+
data.tar.gz: 1557f284030e803a3eb4a24678e99d373f7fe4f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea3b1d9c597fa378ca6f6fb7c9bd3a4e63f964781839ac7bf1aa9926a7da81fd68c0e417a7d42e405631167e3092b0fa5285d1457bbd4a5cfbb09c941c70ab3f
|
7
|
+
data.tar.gz: ae5e4467e29dbeae65d929579d98201326e45e3d6a7691b00f5c528aae01cb4c554b65eb2ab04b2c55c1562ebb0bfdb3fbbeca49cdaddc75eb19d90bea81e1d4
|
data/README.md
CHANGED
@@ -11,9 +11,22 @@ Do not use this gem in production.
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
+
You can use this gem in two different ways:
|
15
|
+
|
16
|
+
* embedded - talking directly to the database using the Neo4j Java API (only JRuby)
|
17
|
+
* server - talking to the Neo4j Server via HTTP (Both JRuby and MRI)
|
18
|
+
|
19
|
+
### Embedded or Server Neo4j ?
|
20
|
+
|
21
|
+
I suggest you start using the Neo4j server instead of Neo4j embedded because it is easier to use for development.
|
22
|
+
If you later get performance problem (e.g. too many HTTP requests hitting the Neo4j Server)
|
23
|
+
you can try the embedded neo4j with almost no changes in your code base.
|
24
|
+
The embedded neo4j via JRuby also gives you direct access to the Neo4j Java API (e.g. the Neo4j Traversal API)
|
25
|
+
which can be used to do more powerful and efficient traversals.
|
26
|
+
|
14
27
|
### Usage from Neo4j Server
|
15
28
|
|
16
|
-
You need to install the Neo4j server. This can be done by
|
29
|
+
You need to install the Neo4j server. This can be done by using a Rake task.
|
17
30
|
|
18
31
|
|
19
32
|
Install the gem:
|
@@ -27,20 +40,22 @@ Create a Rakefile with the following content:
|
|
27
40
|
require 'neo4j/tasks/neo4j_server'
|
28
41
|
```
|
29
42
|
|
30
|
-
Install and start neo4j:
|
43
|
+
Install and start neo4j by typing:
|
31
44
|
```
|
32
|
-
rake neo4j:install[community-2.0.
|
45
|
+
rake neo4j:install[community-2.0.2]
|
33
46
|
rake neo4j:start
|
34
47
|
```
|
35
48
|
|
49
|
+
|
36
50
|
### Usage from Neo4j Embedded
|
37
51
|
|
38
52
|
The Gemfile contains references to Neo4j Java libraries. Nothing is needed to be installed.
|
39
53
|
The embedded database is only accessible from JRuby (unlike the Neo4j Server).
|
54
|
+
No need to start the server since it is embedded.
|
40
55
|
|
41
56
|
## Neo4j-core API, v3.0
|
42
57
|
|
43
|
-
###
|
58
|
+
### Database Session
|
44
59
|
|
45
60
|
There are currently two available types of session, one for connecting to a neo4j server
|
46
61
|
and one for connecting to the embedded Neo4j database (which requires JRuby).
|
@@ -51,9 +66,22 @@ Open a IRB/Pry session:
|
|
51
66
|
```ruby
|
52
67
|
require 'neo4j-core'
|
53
68
|
# Using Neo4j Server Cypher Database
|
54
|
-
session = Neo4j::Session.open(:server_db
|
69
|
+
session = Neo4j::Session.open(:server_db)
|
70
|
+
```
|
71
|
+
|
72
|
+
### Session Configuration
|
73
|
+
|
74
|
+
Example, Basic Authentication:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
Neo4j::Session.open(:server_db, 'http://my.server', basic_auth: { username: 'username', password: 'password'})
|
55
78
|
```
|
56
79
|
|
80
|
+
The last option hash is passed on to HTTParty. See here for more available options:
|
81
|
+
http://rdoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods
|
82
|
+
|
83
|
+
### Embedded Session
|
84
|
+
|
57
85
|
Using the Neo4j Embedded Database, `:embedded_db`
|
58
86
|
|
59
87
|
```ruby
|
@@ -62,6 +90,15 @@ Using the Neo4j Embedded Database, `:embedded_db`
|
|
62
90
|
session.start
|
63
91
|
```
|
64
92
|
|
93
|
+
To stop the database (only supported via the embedded database) use
|
94
|
+
```
|
95
|
+
session.shutdown
|
96
|
+
session.running? #=> false
|
97
|
+
session.close # make the session not current/default
|
98
|
+
```
|
99
|
+
|
100
|
+
### Session.current
|
101
|
+
|
65
102
|
When a session has been created it will be stored in the `Neo4j::Session` object.
|
66
103
|
Example, get the default session
|
67
104
|
|
@@ -69,6 +106,8 @@ Example, get the default session
|
|
69
106
|
session = Neo4j::Session.current
|
70
107
|
```
|
71
108
|
|
109
|
+
### Multiple Sessions
|
110
|
+
|
72
111
|
The default session is used by all operation unless specified as the last argument.
|
73
112
|
For example create a node with a different session:
|
74
113
|
|
@@ -77,9 +116,9 @@ my_session = Neo4j::Session.create_session(:server_db, "http://localhost:7474")
|
|
77
116
|
Neo4j::Node.create(name: 'kalle', my_session)
|
78
117
|
```
|
79
118
|
|
80
|
-
When using the Neo4j Server: `:server_db`,
|
119
|
+
When using the Neo4j Server: `:server_db`, multiple sessions are supported. They
|
81
120
|
can be created using the open_named method. This method takes two extra parameters,
|
82
|
-
the second
|
121
|
+
the second parameter is the session name, and the third parameter is whether the new session should over-ride
|
83
122
|
the default session (becoming the session returned by calling `Neo4j::Session.current`).
|
84
123
|
Valid options are true (always become current), false (never become current) and nil (become current if no
|
85
124
|
existing current session).
|
@@ -291,6 +330,27 @@ session.query("START n=node({a_parameter}) RETURN ID(n)", a_parameter: 0)
|
|
291
330
|
session.query(a_parameter: 0) { node("{a_parameter}").neo_id.as(:foo) }
|
292
331
|
```
|
293
332
|
|
333
|
+
The `query` method returns an Enumeration of Hash values.
|
334
|
+
|
335
|
+
Example of loading Neo4j::Nodes from a cypher query
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
result = session.query("START n=node(*) RETURN ID(n)")
|
339
|
+
nodes = result.map do |key_values|
|
340
|
+
# just one column is returned in this example - :'ID(n)'
|
341
|
+
node_id = key_values.values[0]
|
342
|
+
Neo4j::Node.load(node_id)
|
343
|
+
end
|
344
|
+
```
|
345
|
+
|
346
|
+
Example, using the name of the column
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
result = session.query("START n=node(0) RETURN ID(n) as mykey")
|
350
|
+
Neo4j::Node.load(result.first[:mykey])
|
351
|
+
```
|
352
|
+
|
353
|
+
|
294
354
|
## Implementation:
|
295
355
|
|
296
356
|
All method prefixed with `_` gives direct access to the java layer/rest layer.
|
@@ -37,7 +37,10 @@ module Neo4j::Core
|
|
37
37
|
# Cypher Helper
|
38
38
|
def cypher_prop_list(props)
|
39
39
|
return "" unless props
|
40
|
-
|
40
|
+
|
41
|
+
properties_to_set = props.reject {|k,v| v.nil? }
|
42
|
+
|
43
|
+
list = properties_to_set.map{|k,v| "#{k} : #{escape_value(v)}"}.join(',')
|
41
44
|
"{#{list}}"
|
42
45
|
end
|
43
46
|
|
data/lib/neo4j-core/version.rb
CHANGED
data/lib/neo4j-server.rb
CHANGED
@@ -1,22 +1,38 @@
|
|
1
1
|
module Neo4j::Server
|
2
2
|
|
3
3
|
# Plugin
|
4
|
-
Neo4j::Session.register_db(:server_db) do |
|
5
|
-
|
6
|
-
raise "Server not available on #{endpoint_url} (response code #{response.code})" unless response.code == 200
|
7
|
-
root_data = JSON.parse(response.body)
|
8
|
-
data_url = root_data['data']
|
9
|
-
data_url << '/' unless data_url.end_with?('/')
|
10
|
-
Neo4j::Server::CypherSession.new(data_url)
|
4
|
+
Neo4j::Session.register_db(:server_db) do |*url_opts|
|
5
|
+
Neo4j::Server::CypherSession.open(*url_opts)
|
11
6
|
end
|
12
7
|
|
13
8
|
class CypherSession < Neo4j::Session
|
14
9
|
include Resource
|
15
10
|
include Neo4j::Core::CypherTranslator
|
16
|
-
|
11
|
+
|
17
12
|
alias_method :super_query, :query
|
18
13
|
|
19
|
-
|
14
|
+
|
15
|
+
# Opens a session to the database
|
16
|
+
# @see Neo4j::Session#open
|
17
|
+
#
|
18
|
+
# @param url - defaults to 'http://localhost:7474' if not given
|
19
|
+
# @params - see https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb for supported
|
20
|
+
# HTTParty options
|
21
|
+
def self.open(endpoint_url=nil, params = {})
|
22
|
+
endpoint = Neo4jServerEndpoint.new(params)
|
23
|
+
url = endpoint_url || 'http://localhost:7474'
|
24
|
+
response = endpoint.get(url)
|
25
|
+
raise "Server not available on #{url} (response code #{response.code})" unless response.code == 200
|
26
|
+
|
27
|
+
root_data = JSON.parse(response.body)
|
28
|
+
data_url = root_data['data']
|
29
|
+
data_url << '/' unless data_url.end_with?('/')
|
30
|
+
|
31
|
+
CypherSession.new(data_url, endpoint)
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(data_url, endpoint = nil)
|
35
|
+
@endpoint = endpoint || Neo4jServerEndpoint.new(data_url)
|
20
36
|
Neo4j::Session.register(self)
|
21
37
|
initialize_resource(data_url)
|
22
38
|
Neo4j::Session._notify_listeners(:session_available, self)
|
@@ -27,7 +43,7 @@ module Neo4j::Server
|
|
27
43
|
end
|
28
44
|
|
29
45
|
def initialize_resource(data_url)
|
30
|
-
response =
|
46
|
+
response = @endpoint.get(data_url)
|
31
47
|
expect_response_code(response,200)
|
32
48
|
data_resource = JSON.parse(response.body)
|
33
49
|
raise "No data_resource for #{response.body}" unless data_resource
|
@@ -41,7 +57,7 @@ module Neo4j::Server
|
|
41
57
|
end
|
42
58
|
|
43
59
|
def begin_tx
|
44
|
-
Thread.current[:neo4j_curr_tx] = wrap_resource(self, 'transaction', CypherTransaction, nil, :post)
|
60
|
+
Thread.current[:neo4j_curr_tx] = wrap_resource(self, 'transaction', CypherTransaction, nil, :post, @endpoint)
|
45
61
|
end
|
46
62
|
|
47
63
|
def create_node(props=nil, labels=[])
|
@@ -78,7 +94,7 @@ module Neo4j::Server
|
|
78
94
|
end
|
79
95
|
|
80
96
|
def indexes(label)
|
81
|
-
response =
|
97
|
+
response = @endpoint.get("#{@resource_url}schema/index/#{label}")
|
82
98
|
expect_response_code(response, 200)
|
83
99
|
data_resource = JSON.parse(response.body)
|
84
100
|
|
@@ -135,7 +151,7 @@ module Neo4j::Server
|
|
135
151
|
else
|
136
152
|
url = resource_url('cypher')
|
137
153
|
q = params.nil? ? {query: q} : {query: q, params: params}
|
138
|
-
response =
|
154
|
+
response = @endpoint.post(url, headers: resource_headers, body: q.to_json)
|
139
155
|
CypherResponse.create_with_no_tx(response)
|
140
156
|
end
|
141
157
|
end
|
@@ -14,7 +14,8 @@ module Neo4j::Server
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def initialize(db, response, url)
|
17
|
+
def initialize(db, response, url, endpoint)
|
18
|
+
@endpoint = endpoint
|
18
19
|
@commit_url = response['commit']
|
19
20
|
@exec_url = response.headers['location']
|
20
21
|
init_resource_data(response, url)
|
@@ -39,7 +40,7 @@ module Neo4j::Server
|
|
39
40
|
statement[:statement].gsub!("{ #{k} }", "#{escape_value(v)}")
|
40
41
|
end
|
41
42
|
end
|
42
|
-
response =
|
43
|
+
response = @endpoint.post(@exec_url, headers: resource_headers, body: body.to_json)
|
43
44
|
|
44
45
|
first_result = response['results'][0]
|
45
46
|
cr = CypherResponse.new(response, true)
|
@@ -68,9 +69,9 @@ module Neo4j::Server
|
|
68
69
|
def finish
|
69
70
|
Neo4j::Transaction.unregister(self)
|
70
71
|
if failure?
|
71
|
-
response =
|
72
|
+
response = @endpoint.delete(@exec_url, headers: resource_headers)
|
72
73
|
else
|
73
|
-
response =
|
74
|
+
response = @endpoint.post(@commit_url, headers: resource_headers)
|
74
75
|
end
|
75
76
|
expect_response_code(response,200)
|
76
77
|
response
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Neo4j::Server
|
2
|
+
class Neo4jServerEndpoint
|
3
|
+
def initialize(params = {})
|
4
|
+
@params = params
|
5
|
+
end
|
6
|
+
|
7
|
+
def merged_options(options)
|
8
|
+
options.merge!(@params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(url, options={})
|
12
|
+
HTTParty.get(url, merged_options(options))
|
13
|
+
end
|
14
|
+
|
15
|
+
def post(url, options={})
|
16
|
+
HTTParty.post(url, merged_options(options))
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(url, options={})
|
20
|
+
HTTParty.delete(url, merged_options(options))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -16,10 +16,10 @@ module Neo4j
|
|
16
16
|
end
|
17
17
|
|
18
18
|
|
19
|
-
def wrap_resource(db, rel, resource_class, args=nil, verb=:get, payload=nil)
|
19
|
+
def wrap_resource(db, rel, resource_class, args=nil, verb=:get, payload=nil, endpoint)
|
20
20
|
url = resource_url(rel, args)
|
21
|
-
response =
|
22
|
-
response.code == 404 ? nil : resource_class.new(db, response, url)
|
21
|
+
response = endpoint.send(verb, url, headers: {'Content-Type' => 'application/json'}, body: payload)
|
22
|
+
response.code == 404 ? nil : resource_class.new(db, response, url, endpoint)
|
23
23
|
end
|
24
24
|
|
25
25
|
def resource_url(rel=nil, args=nil)
|
data/lib/neo4j/session.rb
CHANGED
@@ -89,7 +89,8 @@ module Neo4j
|
|
89
89
|
end
|
90
90
|
|
91
91
|
class << self
|
92
|
-
# Creates a new session
|
92
|
+
# Creates a new session to Neo4j
|
93
|
+
# @see also Neo4j::Server::CypherSession#open for :server_db params
|
93
94
|
# @param db_type the type of database, e.g. :embedded_db, or :server_db
|
94
95
|
def open(db_type, *params)
|
95
96
|
register(create_session(db_type, params))
|
data/neo4j-core.gemspec
CHANGED
@@ -12,7 +12,9 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.email = 'andreas.ronge@gmail.com'
|
13
13
|
s.homepage = "http://github.com/andreasronge/neo4j-core/tree"
|
14
14
|
s.rubyforge_project = 'neo4j-core'
|
15
|
-
s.summary = "A graph database for
|
15
|
+
s.summary = "A graph database for Ruby"
|
16
|
+
s.license = 'MIT'
|
17
|
+
|
16
18
|
s.description = <<-EOF
|
17
19
|
You can think of Neo4j as a high-performance graph engine with all the features of a mature and robust database.
|
18
20
|
The programmer works with an object-oriented, flexible network structure rather than with strict and static tables
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4j-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.alpha.
|
4
|
+
version: 3.0.0.alpha.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Ronge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/neo4j-server/cypher_response.rb
|
103
103
|
- lib/neo4j-server/cypher_session.rb
|
104
104
|
- lib/neo4j-server/cypher_transaction.rb
|
105
|
+
- lib/neo4j-server/neo4j_server_endpoint.rb
|
105
106
|
- lib/neo4j-server/resource.rb
|
106
107
|
- lib/neo4j/entity_equality.rb
|
107
108
|
- lib/neo4j/label.rb
|
@@ -114,7 +115,8 @@ files:
|
|
114
115
|
- lib/neo4j/transaction.rb
|
115
116
|
- neo4j-core.gemspec
|
116
117
|
homepage: http://github.com/andreasronge/neo4j-core/tree
|
117
|
-
licenses:
|
118
|
+
licenses:
|
119
|
+
- MIT
|
118
120
|
metadata: {}
|
119
121
|
post_install_message:
|
120
122
|
rdoc_options:
|
@@ -142,6 +144,6 @@ rubyforge_project: neo4j-core
|
|
142
144
|
rubygems_version: 2.2.2
|
143
145
|
signing_key:
|
144
146
|
specification_version: 4
|
145
|
-
summary: A graph database for
|
147
|
+
summary: A graph database for Ruby
|
146
148
|
test_files: []
|
147
149
|
has_rdoc: true
|