neo4j-core 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neo4j-core.rb +1 -0
- data/lib/neo4j-core/query.rb +21 -3
- data/lib/neo4j-core/query_find_in_batches.rb +41 -0
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-server/cypher_session.rb +12 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20021948746b82897d81ebb31d4a59767358dcd2
|
4
|
+
data.tar.gz: 6cd5c4daf6d4a3ba0a0e42265633bbefc3e48a91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8676dfad9c081b81a232d32d4fd9466a47918ad4de2ccfbd0d4bff7215b1fe2050e9d395d23d04f5e40c8c52c6c92ec546c746f60aa7d959a511c647e9a742c7
|
7
|
+
data.tar.gz: 07531aa910bac193d36a0c16b76df81ef7862579c3981d0f4bce5dacb130aeb744445336a65b9b163d0c3d4d4a49fd518e7d492849b466025532ee27dce7b7b4
|
data/lib/neo4j-core.rb
CHANGED
data/lib/neo4j-core/query.rb
CHANGED
@@ -12,6 +12,7 @@ module Neo4j::Core
|
|
12
12
|
# http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html
|
13
13
|
class Query
|
14
14
|
include Neo4j::Core::QueryClauses
|
15
|
+
include Neo4j::Core::QueryFindInBatches
|
15
16
|
|
16
17
|
def initialize(options = {})
|
17
18
|
@session = options[:session] || Neo4j::Session.current
|
@@ -113,6 +114,14 @@ module Neo4j::Core
|
|
113
114
|
alias_method :offset, :skip
|
114
115
|
alias_method :order_by, :order
|
115
116
|
|
117
|
+
# Clears out previous order clauses and allows only for those specified by args
|
118
|
+
def reorder(*args)
|
119
|
+
query = self.copy
|
120
|
+
|
121
|
+
query.remove_clause_class(OrderClause)
|
122
|
+
query.order(*args)
|
123
|
+
end
|
124
|
+
|
116
125
|
# Works the same as the #set method, but when given a nested array it will set properties rather than setting entire objects
|
117
126
|
# @example
|
118
127
|
# # Creates a query representing the cypher: MATCH (n:Person) SET n.age = 19
|
@@ -210,7 +219,7 @@ module Neo4j::Core
|
|
210
219
|
end
|
211
220
|
|
212
221
|
def return_query(columns)
|
213
|
-
query = self.
|
222
|
+
query = self.copy
|
214
223
|
query.remove_clause_class(ReturnClause)
|
215
224
|
|
216
225
|
columns = columns.map do |column_definition|
|
@@ -270,6 +279,15 @@ module Neo4j::Core
|
|
270
279
|
end.params(other_query._params)
|
271
280
|
end
|
272
281
|
|
282
|
+
MEMOIZED_INSTANCE_VARIABLES = [:response, :merge_params]
|
283
|
+
def copy
|
284
|
+
self.dup.tap do |query|
|
285
|
+
MEMOIZED_INSTANCE_VARIABLES.each do |var|
|
286
|
+
query.instance_variable_set("@#{var}", nil)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
273
291
|
protected
|
274
292
|
attr_accessor :session, :options, :clauses, :_params
|
275
293
|
|
@@ -285,14 +303,14 @@ module Neo4j::Core
|
|
285
303
|
private
|
286
304
|
|
287
305
|
def build_deeper_query(clause_class, args = {}, options = {})
|
288
|
-
self.
|
306
|
+
self.copy.tap do |new_query|
|
289
307
|
new_query.add_clauses [nil] if [nil, WithClause].include?(clause_class)
|
290
308
|
new_query.add_clauses clause_class.from_args(args, options) if clause_class
|
291
309
|
end
|
292
310
|
end
|
293
311
|
|
294
312
|
def break_deeper_query
|
295
|
-
self.
|
313
|
+
self.copy.tap do |new_query|
|
296
314
|
new_query.add_clauses [nil]
|
297
315
|
end
|
298
316
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Neo4j::Core
|
2
|
+
module QueryFindInBatches
|
3
|
+
|
4
|
+
def find_in_batches(node_var, prop_var, options = {})
|
5
|
+
invalid_keys = options.keys.map(&:to_sym) - [:batch_size]
|
6
|
+
raise ArgumentError, "Invalid keys: #{invalid_keys.join(', ')}" if not invalid_keys.empty?
|
7
|
+
|
8
|
+
batch_size = options.delete(:batch_size) || 1000
|
9
|
+
|
10
|
+
query = self.reorder(node_var => prop_var).limit(batch_size)
|
11
|
+
|
12
|
+
records = query.to_a
|
13
|
+
|
14
|
+
while records.any?
|
15
|
+
records_size = records.size
|
16
|
+
primary_key_offset = begin
|
17
|
+
records.last.send(node_var).send(prop_var)
|
18
|
+
rescue NoMethodError
|
19
|
+
begin
|
20
|
+
records.last.send(node_var)[prop_var.to_sym]
|
21
|
+
rescue NoMethodError
|
22
|
+
records.last.send("#{node_var}.#{prop_var}") # In case we're explicitly returning it
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
yield records
|
27
|
+
|
28
|
+
break if records_size < batch_size
|
29
|
+
|
30
|
+
records = query.where("#{node_var}.#{prop_var} > {primary_key_offset}").params(primary_key_offset: primary_key_offset).to_a
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_each(*args)
|
35
|
+
find_in_batches(*args) do |batch|
|
36
|
+
batch.each { |result| yield result }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/lib/neo4j-core/version.rb
CHANGED
@@ -8,7 +8,7 @@ module Neo4j::Server
|
|
8
8
|
class CypherSession < Neo4j::Session
|
9
9
|
include Resource
|
10
10
|
include Neo4j::Core::CypherTranslator
|
11
|
-
|
11
|
+
|
12
12
|
alias_method :super_query, :query
|
13
13
|
attr_reader :connection
|
14
14
|
|
@@ -36,6 +36,7 @@ module Neo4j::Server
|
|
36
36
|
# @param [String] endpoint_url - the url to the neo4j server, defaults to 'http://localhost:7474'
|
37
37
|
# @param [Hash] params faraday params, see #create_connection or an already created faraday connection
|
38
38
|
def self.open(endpoint_url=nil, params = {})
|
39
|
+
extract_basic_auth(endpoint_url, params)
|
39
40
|
connection = params[:connection] || create_connection(params)
|
40
41
|
url = endpoint_url || 'http://localhost:7474'
|
41
42
|
response = connection.get(url)
|
@@ -48,6 +49,15 @@ module Neo4j::Server
|
|
48
49
|
CypherSession.new(data_url, connection)
|
49
50
|
end
|
50
51
|
|
52
|
+
def self.extract_basic_auth(url, params)
|
53
|
+
return unless url && URI(url).userinfo
|
54
|
+
params[:basic_auth] = {
|
55
|
+
username: URI(url).user,
|
56
|
+
password: URI(url).password
|
57
|
+
}
|
58
|
+
end
|
59
|
+
private_class_method :extract_basic_auth
|
60
|
+
|
51
61
|
def initialize(data_url, connection)
|
52
62
|
@connection = connection
|
53
63
|
Neo4j::Session.register(self)
|
@@ -168,7 +178,7 @@ module Neo4j::Server
|
|
168
178
|
|
169
179
|
def find_nodes(label_name, key, value)
|
170
180
|
value = "'#{value}'" if value.is_a? String
|
171
|
-
|
181
|
+
|
172
182
|
response = _query_or_fail <<-CYPHER
|
173
183
|
MATCH (n:`#{label_name}`)
|
174
184
|
WHERE n.#{key} = #{value}
|
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.
|
4
|
+
version: 3.0.5
|
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-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- lib/neo4j-core/label.rb
|
155
155
|
- lib/neo4j-core/query.rb
|
156
156
|
- lib/neo4j-core/query_clauses.rb
|
157
|
+
- lib/neo4j-core/query_find_in_batches.rb
|
157
158
|
- lib/neo4j-core/version.rb
|
158
159
|
- lib/neo4j-embedded.rb
|
159
160
|
- lib/neo4j-embedded/cypher_response.rb
|
@@ -214,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
215
|
version: '0'
|
215
216
|
requirements: []
|
216
217
|
rubyforge_project: neo4j-core
|
217
|
-
rubygems_version: 2.
|
218
|
+
rubygems_version: 2.4.2
|
218
219
|
signing_key:
|
219
220
|
specification_version: 4
|
220
221
|
summary: A graph database for Ruby
|