neo4j-core 6.1.1 → 6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-server/cypher_response.rb +19 -46
- metadata +2 -3
- data/lib/neo4j/core/label.rb +0 -127
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca37281eae5c190ad058ab504fb1e6ffb5fc682c
|
4
|
+
data.tar.gz: 9541360552ce0e0f26651fb7c0d1a6d3ff8e732c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d66bb9bb42948ffce0f3de794afef2001ffbe9500d5c4bcc78de01865ae47d390db99140f7ef01dc62b11c69bf27b27cb73857f130dcd8abcca48a053680694
|
7
|
+
data.tar.gz: 6553b27e42bea15397c6cb061c2e89dcda9805b45c5b99005e9707eb0b76123d71cfc407cd28ea90db18ee33b8fbeeb749674a129c065471fc42237da29c0a0a
|
data/lib/neo4j-core/version.rb
CHANGED
@@ -55,11 +55,8 @@ module Neo4j
|
|
55
55
|
|
56
56
|
def to_node_enumeration(cypher = EMPTY_STRING, session = Neo4j::Session.current)
|
57
57
|
Enumerator.new do |yielder|
|
58
|
-
@result_index = 0
|
59
58
|
to_struct_enumeration(cypher).each do |row|
|
60
|
-
@row_index = 0
|
61
59
|
yielder << row_pair_in_struct(row, session)
|
62
|
-
@result_index += 1
|
63
60
|
end
|
64
61
|
end
|
65
62
|
end
|
@@ -68,7 +65,6 @@ module Neo4j
|
|
68
65
|
@struct.new.tap do |result|
|
69
66
|
row.each_pair do |column, value|
|
70
67
|
result[column] = map_row_value(value, session)
|
71
|
-
@row_index += 1
|
72
68
|
end
|
73
69
|
end
|
74
70
|
end
|
@@ -84,17 +80,10 @@ module Neo4j
|
|
84
80
|
end
|
85
81
|
|
86
82
|
def hash_value_as_object(value, session)
|
87
|
-
|
88
|
-
|
89
|
-
data = mapped_rest_data
|
90
|
-
elsif [:node, :relationship].include?(identify_entity(value))
|
91
|
-
add_entity_id(value)
|
92
|
-
data = value
|
93
|
-
else
|
94
|
-
return value
|
95
|
-
end
|
83
|
+
return value unless [:node, :relationship].include?(identify_entity(value))
|
84
|
+
add_entity_id(value)
|
96
85
|
|
97
|
-
basic_obj = (node?(value) ? CypherNode : CypherRelationship).new(session,
|
86
|
+
basic_obj = (node?(value) ? CypherNode : CypherRelationship).new(session, value)
|
98
87
|
unwrapped? ? basic_obj : basic_obj.wrapper
|
99
88
|
end
|
100
89
|
|
@@ -112,11 +101,7 @@ module Neo4j
|
|
112
101
|
end
|
113
102
|
|
114
103
|
def looks_like_an_object?(value)
|
115
|
-
|
116
|
-
mapped_rest_data[:outgoing_relationships] || (mapped_rest_data[:start] && mapped_rest_data[:properties])
|
117
|
-
else
|
118
|
-
value[:labels] || value[:type]
|
119
|
-
end
|
104
|
+
value[:labels] || value[:type]
|
120
105
|
end
|
121
106
|
|
122
107
|
def unwrapped!
|
@@ -128,7 +113,7 @@ module Neo4j
|
|
128
113
|
end
|
129
114
|
|
130
115
|
def node?(value)
|
131
|
-
|
116
|
+
value[:labels]
|
132
117
|
end
|
133
118
|
|
134
119
|
attr_reader :struct
|
@@ -151,7 +136,6 @@ module Neo4j
|
|
151
136
|
def first_data
|
152
137
|
if @uncommited
|
153
138
|
@data.first[:row].first
|
154
|
-
# data.is_a?(Hash) ? {'data' => data, 'id' => id} : data
|
155
139
|
else
|
156
140
|
data = @data[0][0]
|
157
141
|
data.is_a?(Hash) ? add_entity_id(data) : data
|
@@ -167,11 +151,6 @@ module Neo4j
|
|
167
151
|
data
|
168
152
|
end
|
169
153
|
|
170
|
-
def add_transaction_entity_id
|
171
|
-
mapped_rest_data[:id] = mapped_rest_data[:self].split('/').last.to_i
|
172
|
-
mapped_rest_data
|
173
|
-
end
|
174
|
-
|
175
154
|
def error?
|
176
155
|
!!@error
|
177
156
|
end
|
@@ -191,7 +170,18 @@ module Neo4j
|
|
191
170
|
end
|
192
171
|
|
193
172
|
def each_data_row
|
194
|
-
data.each
|
173
|
+
data.each do |r|
|
174
|
+
yieldable = if @uncommitted
|
175
|
+
r[:row]
|
176
|
+
else
|
177
|
+
transaction_row?(r) ? r[:rest] : r
|
178
|
+
end
|
179
|
+
yield yieldable
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def transaction_response?
|
184
|
+
response.respond_to?(:body) && !response.body[:commit].nil?
|
195
185
|
end
|
196
186
|
|
197
187
|
def set_data(response)
|
@@ -244,27 +234,10 @@ module Neo4j
|
|
244
234
|
end
|
245
235
|
end
|
246
236
|
|
247
|
-
def transaction_response?
|
248
|
-
response.respond_to?(:body) && !response.body[:commit].nil?
|
249
|
-
end
|
250
|
-
|
251
|
-
def rest_data
|
252
|
-
@result_index = @row_index = 0
|
253
|
-
mapped_rest_data
|
254
|
-
end
|
255
|
-
|
256
|
-
def rest_data_with_id
|
257
|
-
rest_data[:id] = mapped_rest_data[:self].split('/').last.to_i
|
258
|
-
rest_data
|
259
|
-
end
|
260
|
-
|
261
237
|
private
|
262
238
|
|
263
|
-
|
264
|
-
|
265
|
-
def mapped_rest_data
|
266
|
-
data = response.body[:results][0][:data][result_index][:rest][row_index]
|
267
|
-
data.is_a?(Array) ? data.first : data
|
239
|
+
def transaction_row?(row)
|
240
|
+
row.is_a?(Hash) && row[:rest] && row[:row]
|
268
241
|
end
|
269
242
|
end
|
270
243
|
end
|
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: 6.1.
|
4
|
+
version: 6.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Ronge, Chris Grigg, Brian Underwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -285,7 +285,6 @@ files:
|
|
285
285
|
- lib/neo4j/core/cypher_session/responses/http.rb
|
286
286
|
- lib/neo4j/core/cypher_session/result.rb
|
287
287
|
- lib/neo4j/core/instrumentable.rb
|
288
|
-
- lib/neo4j/core/label.rb
|
289
288
|
- lib/neo4j/core/node.rb
|
290
289
|
- lib/neo4j/core/path.rb
|
291
290
|
- lib/neo4j/core/relationship.rb
|
data/lib/neo4j/core/label.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module Core
|
3
|
-
class Label
|
4
|
-
attr_reader :name
|
5
|
-
|
6
|
-
def initialize(name, session)
|
7
|
-
@name = name
|
8
|
-
@session = session
|
9
|
-
schema_threads = []
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_index(property, options = {})
|
13
|
-
puts "create_index(#{property.inspect}, #{options.inspect})"
|
14
|
-
validate_index_options!(options)
|
15
|
-
properties = property.is_a?(Array) ? property.join(',') : property
|
16
|
-
schema_query("CREATE INDEX ON :`#{@name}`(#{properties})")
|
17
|
-
end
|
18
|
-
|
19
|
-
def drop_index(property, options = {})
|
20
|
-
puts "drop_index(#{property.inspect}, #{options.inspect})"
|
21
|
-
validate_index_options!(options)
|
22
|
-
schema_query("DROP INDEX ON :`#{@name}`(#{property})")
|
23
|
-
end
|
24
|
-
|
25
|
-
# Creates a neo4j constraint on a property
|
26
|
-
# See http://docs.neo4j.org/chunked/stable/query-constraints.html
|
27
|
-
# @example
|
28
|
-
# label = Neo4j::Label.create(:person, session)
|
29
|
-
# label.create_constraint(:name, {type: :unique}, session)
|
30
|
-
#
|
31
|
-
def create_constraint(property, constraints)
|
32
|
-
puts "create_constraint(#{property.inspect}, #{constraints.inspect})"
|
33
|
-
cypher = case constraints[:type]
|
34
|
-
when :unique
|
35
|
-
"CREATE CONSTRAINT ON (n:`#{name}`) ASSERT n.`#{property}` IS UNIQUE"
|
36
|
-
else
|
37
|
-
fail "Not supported constrain #{constraints.inspect} for property #{property} (expected :type => :unique)"
|
38
|
-
end
|
39
|
-
schema_query(cypher)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Drops a neo4j constraint on a property
|
43
|
-
# See http://docs.neo4j.org/chunked/stable/query-constraints.html
|
44
|
-
# @example
|
45
|
-
# label = Neo4j::Label.create(:person, session)
|
46
|
-
# label.create_constraint(:name, {type: :unique}, session)
|
47
|
-
# label.drop_constraint(:name, {type: :unique}, session)
|
48
|
-
#
|
49
|
-
def drop_constraint(property, constraint)
|
50
|
-
puts "drop_constraint(#{property.inspect}, #{constraint.inspect})"
|
51
|
-
cypher = case constraint[:type]
|
52
|
-
when :unique
|
53
|
-
"DROP CONSTRAINT ON (n:`#{name}`) ASSERT n.`#{property}` IS UNIQUE"
|
54
|
-
else
|
55
|
-
fail "Not supported constrain #{constraint.inspect}"
|
56
|
-
end
|
57
|
-
schema_query(cypher)
|
58
|
-
end
|
59
|
-
|
60
|
-
def indexes
|
61
|
-
@session.indexes_for_label(@name)
|
62
|
-
end
|
63
|
-
|
64
|
-
def index?(property)
|
65
|
-
indexes.include?(property)
|
66
|
-
end
|
67
|
-
|
68
|
-
def uniqueness_constraints
|
69
|
-
@session.uniqueness_constraints_for_label(@name)
|
70
|
-
end
|
71
|
-
|
72
|
-
def uniqueness_constraint?(property)
|
73
|
-
uniqueness_constraints.include?(property)
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.wait_for_schema_changes(session)
|
77
|
-
schema_threads(session).map(&:join)
|
78
|
-
set_schema_threads(session, [])
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
# Store schema threads on the session so that we can easily wait for all
|
84
|
-
# threads on a session regardless of label
|
85
|
-
def schema_threads
|
86
|
-
self.class.schema_threads(@session)
|
87
|
-
end
|
88
|
-
|
89
|
-
def schema_threads=(array)
|
90
|
-
self.class.set_schema_threads(@session, array)
|
91
|
-
end
|
92
|
-
|
93
|
-
def self.schema_threads(session)
|
94
|
-
session.instance_variable_get('@_schema_threads') || []
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.set_schema_threads(session, array)
|
98
|
-
session.instance_variable_set('@_schema_threads', array)
|
99
|
-
end
|
100
|
-
|
101
|
-
# If there is a transaction going on, this could block
|
102
|
-
# So we run in a thread and it will go through at the next opportunity
|
103
|
-
def schema_query(cypher)
|
104
|
-
Thread.new do
|
105
|
-
begin
|
106
|
-
puts 'Starting transaction for schema query...'
|
107
|
-
@session.transaction do |tx|
|
108
|
-
puts 'Executing schema query...'
|
109
|
-
tx.query(cypher)
|
110
|
-
puts 'Executed schema query...'
|
111
|
-
end
|
112
|
-
rescue Exception => e
|
113
|
-
puts e.message
|
114
|
-
puts e.backtrace
|
115
|
-
end
|
116
|
-
end.tap do |thread|
|
117
|
-
schema_threads << thread
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def validate_index_options!(options)
|
122
|
-
return unless options[:type] && options[:type] != :exact
|
123
|
-
fail "Type #{options[:type]} is not supported"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|