neo4j-core 5.0.10 → 5.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 973a3091e4ac4ffe027b846627a315a70b79e182
4
- data.tar.gz: d9cc32add98996c8efacb94e44034f78cd2c39b3
3
+ metadata.gz: 413db701027dd75c0757902fba22db6a5b289781
4
+ data.tar.gz: 59d07ba453f252c053fbd6b353b3604415cd3a0f
5
5
  SHA512:
6
- metadata.gz: 38e2ebd378bfcccc0fad41b1adcae148da01a6f692f978c3bb134593ad7e2bcc93cb4e3ea7ca637386a4e747442ff2db232ef9eed18d551334c038a109b9f1c3
7
- data.tar.gz: c136b1a82abad7ca652b516cd4a3e50da7170a0cc4b6e529f8134d30cb734886f0d56351d13d0304faff390ffa590cb611931ddbd887a6605d9ad143c4288034
6
+ metadata.gz: cf46b06d8cf1c4b4152fe7ce4f870ca019cdb475d06a2e2d902db223c7d6d2c8abf20b44cba5a352e3e3b4122d4e79e698bdc105a169e41fdc51bca506958474
7
+ data.tar.gz: 9dcdf5e2fdb993c3de4203a0e21029bc497fd6562096bdd6b76b761565c0e56206f16cccd2bc449d5625c8235931f4312810697ed2b547a41d3fb42286d98bb1
data/Gemfile CHANGED
@@ -2,20 +2,16 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'zip'
6
-
7
5
  # gem 'neo4j-advanced', '>= 1.8.1', '< 2.0', :require => false
8
6
  # gem 'neo4j-enterprise', '>= 1.8.1', '< 2.0', :require => false
9
7
 
10
8
  group 'development' do
11
9
  gem 'guard-rspec', require: false
12
- gem 'overcommit'
13
10
  end
14
11
 
15
12
  group 'test' do
16
13
  gem 'coveralls', require: false
17
14
  gem 'simplecov-html', require: false
18
- gem 'rake', '>= 0.8.7'
19
15
  gem 'rspec', '~> 3.0'
20
16
  gem 'rspec-its'
21
17
  end
data/README.md CHANGED
@@ -1,25 +1,51 @@
1
- # Neo4j-core v3.0 [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j-core.png)](https://codeclimate.com/github/neo4jrb/neo4j-core) [![Build Status](https://travis-ci.org/neo4jrb/neo4j-core.png)](https://travis-ci.org/neo4jrb/neo4j-core) [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j-core/badge.png?branch=master)](https://coveralls.io/r/neo4jrb/neo4j-core?branch=master) [![PullReview stats](https://www.pullreview.com/github/neo4jrb/neo4j-core/badges/master.svg?)](https://www.pullreview.com/github/neo4jrb/neo4j-core/reviews/master)
1
+ # Neo4j-core [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j-core.png)](https://codeclimate.com/github/neo4jrb/neo4j-core) [![Build Status](https://travis-ci.org/neo4jrb/neo4j-core.png)](https://travis-ci.org/neo4jrb/neo4j-core) [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j-core/badge.png?branch=master)](https://coveralls.io/r/neo4jrb/neo4j-core?branch=master) [![PullReview stats](https://www.pullreview.com/github/neo4jrb/neo4j-core/badges/master.svg?)](https://www.pullreview.com/github/neo4jrb/neo4j-core/reviews/master)
2
2
 
3
3
  A simple Ruby wrapper around the Neo4j graph database that works with the server and embedded Neo4j API. This gem can be used both from JRuby and normal MRI.
4
4
  It can be used standalone without the neo4j gem.
5
5
 
6
6
  ## Documentation
7
7
 
8
- * [3.0 Documentation](https://github.com/neo4jrb/neo4j-core/wiki)
9
- * [2.x Documentation](https://github.com/neo4jrb/neo4j-core/tree/v2.x)
8
+ ### 3.0+ Documentation:
10
9
 
10
+ * http://neo4jrb.readthedocs.org/en/stable/
11
+ * https://github.com/neo4jrb/neo4j-core/wiki
12
+
13
+ ### 2.x Documentation
14
+
15
+ https://github.com/neo4jrb/neo4j-core/tree/v2.x
11
16
 
12
17
  ## Support
13
18
 
14
- * [Neo4j.rb mailing list](https://groups.google.com/forum/#!forum/neo4jrb)
15
- * Consulting support ? ask any of the developers
19
+ ### Issues
20
+
21
+ [![Next Release](https://badge.waffle.io/neo4jrb/neo4j-core.png?label=Next%20Release&title=Next%20Release) ![In Progress](https://badge.waffle.io/neo4jrb/neo4j-core.png?label=In%20Progress&title=In%20Progress) ![In Master](https://badge.waffle.io/neo4jrb/neo4j-core.png?label=In%20Master&title=In%20Master)](https://waffle.io/neo4jrb/neo4j-core)
22
+
23
+ [![Post an issue](https://img.shields.io/badge/Bug%3F-Post%20an%20issue!-blue.svg)](https://waffle.io/neo4jrb/neo4j-core)
24
+
25
+
26
+ ### Get Support
27
+
28
+ #### Documentation
29
+
30
+ All new documentation will be done via our [readthedocs](http://neo4jrb.readthedocs.org) site, though some old documentation has yet to be moved from our [wiki](https://github.com/neo4jrb/neo4j/wiki) (also there is the [neo4j-core wiki](https://github.com/neo4jrb/neo4j-core/wiki))
31
+
32
+ #### Contact Us
33
+
34
+ [![StackOverflow](https://img.shields.io/badge/StackOverflow-Ask%20a%20question!-blue.svg)](http://stackoverflow.com/questions/ask?tags=neo4j.rb+neo4j+ruby) [![Gitter](https://img.shields.io/badge/Gitter-Join%20our%20chat!-blue.svg)](https://gitter.im/neo4jrb/neo4j?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Twitter](https://img.shields.io/badge/Twitter-Tweet%20with%20us!-blue.svg)](https://twitter.com/neo4jrb) [![Mailing list](https://img.shields.io/badge/Mailing%20list-Mail%20us!-blue.svg)](https://groups.google.com/forum/#!forum/neo4jrb)
35
+
16
36
 
17
37
  ## Developers
18
38
 
19
- * [Andreas Ronge](https://github.com/neo4jrb)
39
+ ### Original Author
40
+
41
+ * [Andreas Ronge](https://github.com/andreasronge)
42
+
43
+ ### Current Maintainers
44
+
20
45
  * [Brian Underwood](https://github.com/cheerfulstoic)
21
46
  * [Chris Grigg](https://github.com/subvertallchris)
22
47
 
48
+ Consulting support? Contact [Chris](http://subvertallmedia.com/) and/or [Brian](http://www.brian-underwood.codes/)
23
49
 
24
50
  ## Contributing
25
51
 
data/lib/neo4j/label.rb CHANGED
@@ -60,7 +60,6 @@ module Neo4j
60
60
  end
61
61
 
62
62
  class << self
63
- include Neo4j::Core::CypherTranslator
64
63
  INDEX_PATH = '/db/data/schema/index/'
65
64
  CONSTRAINT_PATH = '/db/data/schema/constraint/'
66
65
 
data/lib/neo4j/node.rb CHANGED
@@ -168,7 +168,12 @@ module Neo4j
168
168
  class << self
169
169
  # Creates a node
170
170
  def create(props = nil, *labels_or_db)
171
- session = Neo4j::Core::ArgumentHelper.session(labels_or_db)
171
+ session = if labels_or_db.last.is_a?(Neo4j::Session)
172
+ labels_or_db.pop
173
+ else
174
+ Neo4j::Session.current!
175
+ end
176
+
172
177
  session.create_node(props, labels_or_db)
173
178
  end
174
179
 
@@ -1,18 +1,13 @@
1
1
  module Neo4j
2
2
  module Core
3
- module ArgumentHelper
4
- def self.session(args)
5
- args.last.is_a?(Neo4j::Session) ? args.pop : Neo4j::Session.current!
6
- end
7
- end
8
-
9
3
  module TxMethods
10
4
  def tx_methods(*methods)
11
5
  methods.each do |method|
12
6
  tx_method = "#{method}_in_tx"
13
7
  send(:alias_method, tx_method, method)
14
8
  send(:define_method, method) do |*args, &block|
15
- session = ArgumentHelper.session(args)
9
+ session = args.last.is_a?(Neo4j::Session) ? args.pop : Neo4j::Session.current!
10
+
16
11
  Neo4j::Transaction.run(session.auto_commit?) { send(tx_method, *args, &block) }
17
12
  end
18
13
  end
@@ -18,6 +18,10 @@ module Neo4j
18
18
 
19
19
  attr_accessor :clauses
20
20
 
21
+ class << self
22
+ attr_accessor :pretty_cypher
23
+ end
24
+
21
25
  def initialize(options = {})
22
26
  @session = options[:session] || Neo4j::Session.current
23
27
 
@@ -26,6 +30,10 @@ module Neo4j
26
30
  @_params = {}
27
31
  end
28
32
 
33
+ def inspect
34
+ "#<Query CYPHER: #{ANSI::YELLOW}#{to_cypher.inspect}#{ANSI::CLEAR}>"
35
+ end
36
+
29
37
  # @method start *args
30
38
  # START clause
31
39
  # @return [Query]
@@ -133,6 +141,12 @@ module Neo4j
133
141
  query.order(*args)
134
142
  end
135
143
 
144
+ # Works the same as the #where method, but the clause is surrounded by a
145
+ # Cypher NOT() function
146
+ def where_not(*args)
147
+ build_deeper_query(WhereClause, args, not: true)
148
+ end
149
+
136
150
  # Works the same as the #set method, but when given a nested array it will set properties rather than setting entire objects
137
151
  # @example
138
152
  # # Creates a query representing the cypher: MATCH (n:Person) SET n.age = 19
@@ -174,8 +188,9 @@ module Neo4j
174
188
  def response
175
189
  return @response if @response
176
190
  cypher = to_cypher
191
+ pretty_cypher = to_cypher(pretty: true) if self.class.pretty_cypher
177
192
 
178
- @response = @session._query(cypher, merge_params, context: @options[:context])
193
+ @response = @session._query(cypher, merge_params, context: @options[:context], pretty_cypher: pretty_cypher)
179
194
 
180
195
  if !response.respond_to?(:error?) || !response.error?
181
196
  response
@@ -268,22 +283,27 @@ module Neo4j
268
283
  #
269
284
  # @return [String] Resulting cypher query string
270
285
  EMPTY = ' '
271
- def to_cypher
286
+ NEWLINE = "\n"
287
+ def to_cypher(options = {})
272
288
  cypher_string = PartitionedClauses.new(@clauses).map do |clauses|
273
289
  clauses_by_class = clauses.group_by(&:class)
274
290
 
275
291
  cypher_parts = CLAUSES.map do |clause_class|
276
- clause_class.to_cypher(clauses) if clauses = clauses_by_class[clause_class]
292
+ clause_class.to_cypher(clauses, options) if clauses = clauses_by_class[clause_class]
277
293
  end
278
294
 
279
295
  cypher_parts.compact!
280
- cypher_parts.join(EMPTY).tap(&:strip!)
281
- end.join EMPTY
296
+ cypher_parts.join(options[:pretty] ? NEWLINE : EMPTY).tap(&:strip!)
297
+ end.join(options[:pretty] ? NEWLINE : EMPTY)
282
298
 
283
299
  cypher_string = "CYPHER #{@options[:parser]} #{cypher_string}" if @options[:parser]
284
300
  cypher_string.tap(&:strip!)
285
301
  end
286
302
 
303
+ def print_cypher
304
+ puts to_cypher(pretty: true).gsub(/\e[^m]+m/, '')
305
+ end
306
+
287
307
  # Returns a CYPHER query specifying the union of the callee object's query and the argument's query
288
308
  #
289
309
  # @example
@@ -11,12 +11,12 @@ module Neo4j
11
11
 
12
12
 
13
13
  class Clause
14
- include CypherTranslator
15
14
  UNDERSCORE = '_'
16
15
  COMMA_SPACE = ', '
17
16
  AND = ' AND '
18
17
 
19
18
  attr_accessor :params, :arg
19
+ attr_reader :options
20
20
 
21
21
  def initialize(arg, options = {})
22
22
  @arg = arg
@@ -53,8 +53,10 @@ module Neo4j
53
53
  end
54
54
 
55
55
  def node_from_key_and_value(key, value, options = {})
56
- var = var_from_key_and_value(key, value, options[:prefer] || :var)
57
- label = label_from_key_and_value(key, value, options[:prefer] || :var)
56
+ prefer = options[:prefer] || :var
57
+ var = var_from_key_and_value(key, value, prefer)
58
+ label = label_from_key_and_value(key, value, prefer)
59
+
58
60
  attributes = attributes_from_key_and_value(key, value)
59
61
 
60
62
  prefix_value = value
@@ -131,13 +133,34 @@ module Neo4j
131
133
  new(arg, options) if !arg.respond_to?(:empty?) || !arg.empty?
132
134
  end
133
135
 
134
- def to_cypher(clauses)
136
+ def to_cypher(clauses, options = {})
135
137
  @question_mark_param_index = 1
136
138
 
137
- string = clause_string(clauses)
138
- string.strip!
139
+ string = clause_string(clauses, options)
140
+
141
+ final_keyword = if options[:pretty]
142
+ "#{clause_color}#{keyword}#{ANSI::CLEAR}"
143
+ else
144
+ keyword
145
+ end
146
+
147
+ "#{final_keyword} #{string}" if string.size > 0
148
+ end
149
+
150
+ def clause_string(clauses, options = {})
151
+ join_string = clause_join + (options[:pretty] ? "\n " : '')
152
+
153
+ strings = clause_strings(clauses)
154
+ string = ((options[:pretty] && strings.size > 1) ? "\n " : '')
155
+ string + strings.join(join_string).strip
156
+ end
139
157
 
140
- "#{keyword} #{string}" if string.size > 0
158
+ def clause_join
159
+ ''
160
+ end
161
+
162
+ def clause_color
163
+ ANSI::CYAN
141
164
  end
142
165
  end
143
166
 
@@ -228,8 +251,12 @@ module Neo4j
228
251
  end
229
252
 
230
253
  class << self
231
- def clause_string(clauses)
232
- clauses.map!(&:value).join(Clause::COMMA_SPACE)
254
+ def clause_strings(clauses)
255
+ clauses.map!(&:value)
256
+ end
257
+
258
+ def clause_join
259
+ Clause::COMMA_SPACE
233
260
  end
234
261
  end
235
262
  end
@@ -249,8 +276,16 @@ module Neo4j
249
276
  end
250
277
 
251
278
  class << self
252
- def clause_string(clauses)
253
- clauses.map!(&:value).tap(&:flatten!).map! { |value| "(#{value})" }.join(Clause::AND)
279
+ def clause_strings(clauses)
280
+ clauses.flat_map do |clause|
281
+ Array(clause.value).map do |v|
282
+ (clause.options[:not] ? 'NOT' : '') + "(#{v})"
283
+ end
284
+ end
285
+ end
286
+
287
+ def clause_join
288
+ Clause::AND
254
289
  end
255
290
  end
256
291
 
@@ -302,14 +337,18 @@ module Neo4j
302
337
  end
303
338
 
304
339
  def question_mark_params_param
305
- result = "question_mark_param#{@question_mark_param_index}"
306
- @question_mark_param_index += 1
307
- result
340
+ "question_mark_param#{question_mark_param_index}"
341
+ end
342
+
343
+ def question_mark_param_index
344
+ @question_mark_param_index ||= 1
345
+ @question_mark_param_index.tap do
346
+ @question_mark_param_index += 1
347
+ end
308
348
  end
309
349
  end
310
350
  end
311
351
 
312
-
313
352
  class MatchClause < Clause
314
353
  KEYWORD = 'MATCH'
315
354
 
@@ -322,8 +361,12 @@ module Neo4j
322
361
  end
323
362
 
324
363
  class << self
325
- def clause_string(clauses)
326
- clauses.map!(&:value).join(Clause::COMMA_SPACE)
364
+ def clause_strings(clauses)
365
+ clauses.map!(&:value)
366
+ end
367
+
368
+ def clause_join
369
+ Clause::COMMA_SPACE
327
370
  end
328
371
  end
329
372
  end
@@ -344,8 +387,12 @@ module Neo4j
344
387
  end
345
388
 
346
389
  class << self
347
- def clause_string(clauses)
348
- clauses.map!(&:value).join(Clause::COMMA_SPACE)
390
+ def clause_strings(clauses)
391
+ clauses.map!(&:value)
392
+ end
393
+
394
+ def clause_join
395
+ Clause::COMMA_SPACE
349
396
  end
350
397
  end
351
398
  end
@@ -354,8 +401,12 @@ module Neo4j
354
401
  KEYWORD = 'USING'
355
402
 
356
403
  class << self
357
- def clause_string(clauses)
358
- clauses.map!(&:value).join(" #{keyword} ")
404
+ def clause_strings(clauses)
405
+ clauses.map!(&:value)
406
+ end
407
+
408
+ def clause_join
409
+ " #{keyword} "
359
410
  end
360
411
  end
361
412
  end
@@ -386,8 +437,16 @@ module Neo4j
386
437
  end
387
438
 
388
439
  class << self
389
- def clause_string(clauses)
390
- clauses.map!(&:value).join(', ')
440
+ def clause_strings(clauses)
441
+ clauses.map!(&:value)
442
+ end
443
+
444
+ def clause_join
445
+ ', '
446
+ end
447
+
448
+ def clause_color
449
+ ANSI::GREEN
391
450
  end
392
451
  end
393
452
  end
@@ -398,6 +457,12 @@ module Neo4j
398
457
 
399
458
  class MergeClause < CreateClause
400
459
  KEYWORD = 'MERGE'
460
+
461
+ class << self
462
+ def clause_color
463
+ ANSI::MAGENTA
464
+ end
465
+ end
401
466
  end
402
467
 
403
468
  class DeleteClause < Clause
@@ -408,8 +473,16 @@ module Neo4j
408
473
  end
409
474
 
410
475
  class << self
411
- def clause_string(clauses)
412
- clauses.map!(&:value).join(Clause::COMMA_SPACE)
476
+ def clause_strings(clauses)
477
+ clauses.map!(&:value)
478
+ end
479
+
480
+ def clause_join
481
+ Clause::COMMA_SPACE
482
+ end
483
+
484
+ def clause_color
485
+ ANSI::RED
413
486
  end
414
487
  end
415
488
  end
@@ -435,8 +508,12 @@ module Neo4j
435
508
  end
436
509
 
437
510
  class << self
438
- def clause_string(clauses)
439
- clauses.map!(&:value).join(Clause::COMMA_SPACE)
511
+ def clause_strings(clauses)
512
+ clauses.map!(&:value)
513
+ end
514
+
515
+ def clause_join
516
+ Clause::COMMA_SPACE
440
517
  end
441
518
  end
442
519
  end
@@ -461,8 +538,8 @@ module Neo4j
461
538
  end
462
539
 
463
540
  class << self
464
- def clause_string(clauses)
465
- clauses.last.value
541
+ def clause_strings(clauses)
542
+ [clauses.last.value]
466
543
  end
467
544
  end
468
545
  end
@@ -483,8 +560,8 @@ module Neo4j
483
560
  end
484
561
 
485
562
  class << self
486
- def clause_string(clauses)
487
- clauses.last.value
563
+ def clause_strings(clauses)
564
+ [clauses.last.value]
488
565
  end
489
566
  end
490
567
  end
@@ -510,8 +587,16 @@ module Neo4j
510
587
  end
511
588
 
512
589
  class << self
513
- def clause_string(clauses)
514
- clauses.map!(&:value).join(Clause::COMMA_SPACE)
590
+ def clause_strings(clauses)
591
+ clauses.map!(&:value)
592
+ end
593
+
594
+ def clause_join
595
+ Clause::COMMA_SPACE
596
+ end
597
+
598
+ def clause_color
599
+ ANSI::YELLOW
515
600
  end
516
601
  end
517
602
  end
@@ -550,8 +635,12 @@ module Neo4j
550
635
  end
551
636
 
552
637
  class << self
553
- def clause_string(clauses)
554
- clauses.map!(&:value).join(Clause::COMMA_SPACE)
638
+ def clause_strings(clauses)
639
+ clauses.map!(&:value)
640
+ end
641
+
642
+ def clause_join
643
+ Clause::COMMA_SPACE
555
644
  end
556
645
  end
557
646
  end
@@ -571,8 +660,12 @@ module Neo4j
571
660
  end
572
661
 
573
662
  class << self
574
- def clause_string(clauses)
575
- clauses.map!(&:value).join(' UNWIND ')
663
+ def clause_strings(clauses)
664
+ clauses.map!(&:value)
665
+ end
666
+
667
+ def clause_join
668
+ ' UNWIND '
576
669
  end
577
670
  end
578
671
  end
@@ -602,8 +695,12 @@ module Neo4j
602
695
  end
603
696
 
604
697
  class << self
605
- def clause_string(clauses)
606
- clauses.map!(&:value).join(Clause::COMMA_SPACE)
698
+ def clause_strings(clauses)
699
+ clauses.map!(&:value)
700
+ end
701
+
702
+ def clause_join
703
+ Clause::COMMA_SPACE
607
704
  end
608
705
  end
609
706
  end
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Core
3
- VERSION = '5.0.10'
3
+ VERSION = '5.1.0'
4
4
  end
5
5
  end
data/lib/neo4j-core.rb CHANGED
@@ -9,7 +9,6 @@ require 'neo4j/property_validator'
9
9
  require 'neo4j/property_container'
10
10
  require 'neo4j-core/active_entity'
11
11
  require 'neo4j-core/helpers'
12
- require 'neo4j-core/cypher_translator'
13
12
  require 'neo4j-core/query_find_in_batches'
14
13
  require 'neo4j-core/query'
15
14
 
@@ -4,7 +4,6 @@ Neo4j::Session.register_db(:embedded_db) do |*args|
4
4
  Neo4j::Embedded::EmbeddedSession.new(*args)
5
5
  end
6
6
 
7
-
8
7
  module Neo4j
9
8
  module Embedded
10
9
  class EmbeddedSession < Neo4j::Session
@@ -17,16 +16,22 @@ module Neo4j
17
16
  def_delegator :@graph_db, :begin_tx
18
17
 
19
18
  def initialize(db_location, config = {})
19
+ @config = config
20
20
  @db_location = db_location
21
- @auto_commit = !!config[:auto_commit]
22
- @properties_file = config[:properties_file]
23
- if config[:properties_map]
24
- props = config[:properties_map].each_with_object({}) { |(k, v), m| m[k.to_s.to_java] = v.to_s.to_java }
25
- @properties_map = java.util.HashMap.new(props)
26
- end
21
+ @auto_commit = !!@config[:auto_commit]
22
+ @properties_file = @config[:properties_file]
27
23
  Neo4j::Session.register(self)
28
24
  end
29
25
 
26
+ def properties_map
27
+ return @properties_map if @properties_map
28
+
29
+ props = @config[:properties_map].each_with_object({}) do |(k, v), m|
30
+ m[k.to_s.to_java] = v.to_s.to_java
31
+ end
32
+ @properties_map = java.util.HashMap.new(props)
33
+ end
34
+
30
35
  def db_type
31
36
  :embedded_db
32
37
  end
@@ -138,9 +143,10 @@ module Neo4j
138
143
  # @param [String] q the cypher query as a String
139
144
  # @return (see #query)
140
145
  def _query(query, params = {}, options = {})
141
- ActiveSupport::Notifications.instrument('neo4j.cypher_query', context: options[:context] || 'CYPHER', cypher: query, params: params) do
146
+ ActiveSupport::Notifications.instrument('neo4j.cypher_query', params: params, context: options[:context],
147
+ cypher: query, pretty_cypher: options[:pretty_cypher], params: params) do
142
148
  @engine ||= Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(@graph_db)
143
- @engine.execute(query, Neo4j::Core::HashWithIndifferentAccess.new(params))
149
+ @engine.execute(query, HashWithIndifferentAccess.new(params))
144
150
  end
145
151
  rescue StandardError => e
146
152
  raise Neo4j::Session::CypherError.new(e.message, e.class, 'cypher error')
@@ -13,4 +13,4 @@ require 'neo4j-embedded/embedded_transaction'
13
13
  require 'neo4j-embedded/cypher_response'
14
14
 
15
15
  # TODO: replace this with https://github.com/intridea/hashie gem
16
- require 'neo4j-core/hash_with_indifferent_access'
16
+ require 'active_support/hash_with_indifferent_access'
@@ -2,7 +2,6 @@ module Neo4j
2
2
  module Server
3
3
  class CypherNode < Neo4j::Node
4
4
  include Neo4j::Server::Resource
5
- include Neo4j::Core::CypherTranslator
6
5
  include Neo4j::Core::ActiveEntity
7
6
 
8
7
  def initialize(session, value)
@@ -113,8 +112,6 @@ module Neo4j
113
112
  end
114
113
 
115
114
  def set_label(*label_names)
116
- q = match_start_query
117
-
118
115
  labels_to_add = label_names.map(&:to_sym).uniq
119
116
  labels_to_remove = labels - label_names
120
117
 
@@ -122,10 +119,15 @@ module Neo4j
122
119
  labels_to_add -= common_labels
123
120
  labels_to_remove -= common_labels
124
121
 
125
- q = q.remove(n: labels_to_remove) unless labels_to_remove.empty?
126
- q = q.set(n: labels_to_add) unless labels_to_add.empty?
122
+ query = _set_label_query(labels_to_add, labels_to_remove)
123
+ @session._query_or_fail(query, false) unless (labels_to_add + labels_to_remove).empty?
124
+ end
127
125
 
128
- @session._query_or_fail(q, false) unless (labels_to_add + labels_to_remove).empty?
126
+ def _set_label_query(labels_to_add, labels_to_remove)
127
+ query = match_start_query
128
+ query = query.remove(n: labels_to_remove) unless labels_to_remove.empty?
129
+ query = query.set(n: labels_to_add) unless labels_to_add.empty?
130
+ query
129
131
  end
130
132
 
131
133
  # (see Neo4j::Node#del)
@@ -2,7 +2,6 @@ module Neo4j
2
2
  module Server
3
3
  class CypherRelationship < Neo4j::Relationship
4
4
  include Neo4j::Server::Resource
5
- include Neo4j::Core::CypherTranslator
6
5
  include Neo4j::Core::ActiveEntity
7
6
 
8
7
  def initialize(session, value)
@@ -93,10 +92,17 @@ module Neo4j
93
92
  # (see Neo4j::Relationship#update_props)
94
93
  def update_props(properties)
95
94
  return if properties.empty?
96
- q = "#{match_start} SET " + properties.keys.map do |k|
97
- "n.`#{k}`= #{escape_value(properties[k])}"
95
+
96
+ params = {}
97
+ q = "#{match_start} SET " + properties.keys.each_with_index.map do |k, _i|
98
+ param = k.to_s.tr_s('^a-zA-Z0-9', '_').gsub(/^_+|_+$/, '')
99
+ params[param] = properties[k]
100
+
101
+ "n.`#{k}`= {#{param}}"
98
102
  end.join(',')
99
- @session._query_or_fail(q, false, neo_id: neo_id)
103
+
104
+ @session._query_or_fail(q, false, params.merge(neo_id: neo_id))
105
+
100
106
  properties
101
107
  end
102
108
 
@@ -127,7 +133,7 @@ module Neo4j
127
133
  end
128
134
 
129
135
  def neo_id_integer(id_or_url)
130
- id_or_url.is_a?(Integer) ? id_or_url : id_or_url.match(/\d+$/)[0].to_i
136
+ id_or_url.is_a?(Integer) ? id_or_url : id_or_url.split('/').last.to_i
131
137
  end
132
138
  end
133
139
  end