neography 1.3.14 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/neography/rest.rb +29 -472
  3. data/lib/neography/rest/batch.rb +80 -87
  4. data/lib/neography/rest/clean.rb +8 -10
  5. data/lib/neography/rest/constraints.rb +15 -25
  6. data/lib/neography/rest/cypher.rb +2 -6
  7. data/lib/neography/rest/extensions.rb +4 -8
  8. data/lib/neography/rest/gremlin.rb +2 -6
  9. data/lib/neography/rest/helpers.rb +58 -0
  10. data/lib/neography/rest/node_auto_indexes.rb +54 -8
  11. data/lib/neography/rest/node_indexes.rb +92 -17
  12. data/lib/neography/rest/node_labels.rb +15 -26
  13. data/lib/neography/rest/node_paths.rb +8 -16
  14. data/lib/neography/rest/node_properties.rb +45 -4
  15. data/lib/neography/rest/node_relationships.rb +8 -17
  16. data/lib/neography/rest/node_traversal.rb +7 -63
  17. data/lib/neography/rest/nodes.rb +21 -29
  18. data/lib/neography/rest/other_node_relationships.rb +6 -13
  19. data/lib/neography/rest/relationship_auto_indexes.rb +54 -8
  20. data/lib/neography/rest/relationship_indexes.rb +104 -14
  21. data/lib/neography/rest/relationship_properties.rb +45 -4
  22. data/lib/neography/rest/relationship_types.rb +4 -11
  23. data/lib/neography/rest/relationships.rb +6 -13
  24. data/lib/neography/rest/schema_indexes.rb +8 -16
  25. data/lib/neography/rest/spatial.rb +16 -33
  26. data/lib/neography/rest/transactions.rb +25 -26
  27. data/lib/neography/tasks.rb +2 -2
  28. data/lib/neography/version.rb +1 -1
  29. data/spec/unit/rest/batch_spec.rb +49 -50
  30. data/spec/unit/rest/clean_spec.rb +3 -4
  31. data/spec/unit/rest/constraints_spec.rb +12 -13
  32. data/spec/unit/rest/cypher_spec.rb +3 -4
  33. data/spec/unit/rest/extensions_spec.rb +5 -6
  34. data/spec/unit/rest/gremlin_spec.rb +5 -6
  35. data/spec/unit/rest/helpers_spec.rb +124 -0
  36. data/spec/unit/rest/labels_spec.rb +21 -22
  37. data/spec/unit/rest/node_auto_indexes_spec.rb +23 -24
  38. data/spec/unit/rest/node_indexes_spec.rb +42 -43
  39. data/spec/unit/rest/node_paths_spec.rb +10 -13
  40. data/spec/unit/rest/node_properties_spec.rb +22 -23
  41. data/spec/unit/rest/node_relationships_spec.rb +18 -39
  42. data/spec/unit/rest/node_traversal_spec.rb +4 -97
  43. data/spec/unit/rest/nodes_spec.rb +47 -48
  44. data/spec/unit/rest/relationship_auto_indexes_spec.rb +23 -24
  45. data/spec/unit/rest/relationship_indexes_spec.rb +42 -43
  46. data/spec/unit/rest/relationship_properties_spec.rb +22 -23
  47. data/spec/unit/rest/relationship_types_spec.rb +3 -4
  48. data/spec/unit/rest/relationships_spec.rb +5 -6
  49. data/spec/unit/rest/schema_index_spec.rb +7 -8
  50. data/spec/unit/rest/transactions_spec.rb +10 -11
  51. metadata +27 -31
  52. data/lib/neography/rest/auto_indexes.rb +0 -64
  53. data/lib/neography/rest/indexes.rb +0 -102
  54. data/lib/neography/rest/paths.rb +0 -46
  55. data/lib/neography/rest/properties.rb +0 -56
  56. data/spec/unit/rest/paths_spec.rb +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 609dbff4ea29be76d5d8e5a0a6594c7d4d51b8e4
4
- data.tar.gz: 3e81c09d88b08f30ec36671a37cc2cf18055ccce
3
+ metadata.gz: 794c980fa4c282cc154994ccaa0692c12fdbc39c
4
+ data.tar.gz: c907982ec7c4cf91c073bee34aa595a12305475c
5
5
  SHA512:
6
- metadata.gz: 0d6994e98944f8cb050ad3fd392da299f8edb630fee4b12f6b06f1d5166f5b9dfa6bb137fc2c243b10e3da5c870802079805fca363f4dd9f6dcc39b47714feeb
7
- data.tar.gz: 2a5186feff3c291a6d281103f14b6ed511fe54c47361c575b2e28e5535dbdb7137ca3fe6c24d3cad2cdb29d318c83b51652ea361927adf76748f19f9ba7d1ad2
6
+ metadata.gz: fb834cf346080c36312ec4b2f94efd2826b24838eecc091530d7081021e0ae8c14560a73a8e43448bf27eef2a41ba12b1f0049a00fb0d981c9bbfac0f5a1dcaf
7
+ data.tar.gz: 42b751b7b80957aa9648e34905d3ed48b5b943bc7d6cebc7442ee066587e4c81602fef27d2254beac7b83906d582f768a450fb7f0d9de1a69edd914240f91d8c
@@ -1,13 +1,7 @@
1
1
  require 'forwardable'
2
2
 
3
3
  require 'neography/rest/helpers'
4
- require 'neography/rest/paths'
5
-
6
- require 'neography/rest/properties'
7
- require 'neography/rest/indexes'
8
- require 'neography/rest/auto_indexes'
9
4
  require 'neography/rest/schema_indexes'
10
-
11
5
  require 'neography/rest/nodes'
12
6
  require 'neography/rest/node_properties'
13
7
  require 'neography/rest/node_relationships'
@@ -30,15 +24,36 @@ require 'neography/rest/clean'
30
24
  require 'neography/rest/transactions'
31
25
  require 'neography/rest/spatial'
32
26
  require 'neography/rest/constraints'
33
-
34
27
  require 'neography/errors'
35
-
36
28
  require 'neography/connection'
37
29
 
38
30
  module Neography
39
31
 
40
32
  class Rest
41
33
  include Helpers
34
+ include RelationshipTypes
35
+ include NodeLabels
36
+ include SchemaIndexes
37
+ include Constraints
38
+ include Transactions
39
+ include Nodes
40
+ include NodeProperties
41
+ include Relationships
42
+ include RelationshipProperties
43
+ include NodeRelationships
44
+ include OtherNodeRelationships
45
+ include NodeIndexes
46
+ include NodeAutoIndexes
47
+ include RelationshipIndexes
48
+ include RelationshipAutoIndexes
49
+ include NodeTraversal
50
+ include NodePaths
51
+ include Cypher
52
+ include Gremlin
53
+ include Batch
54
+ include Extensions
55
+ include Spatial
56
+ include Clean
42
57
  extend Forwardable
43
58
 
44
59
  attr_reader :connection
@@ -47,162 +62,13 @@ module Neography
47
62
 
48
63
  def initialize(options = ENV['NEO4J_URL'] || {})
49
64
  @connection = Connection.new(options)
65
+ end
50
66
 
51
- @nodes ||= Nodes.new(@connection)
52
- @node_properties ||= NodeProperties.new(@connection)
53
- @node_relationships ||= NodeRelationships.new(@connection)
54
- @other_node_relationships ||= OtherNodeRelationships.new(@connection)
55
- @node_indexes ||= NodeIndexes.new(@connection)
56
- @node_auto_indexes ||= NodeAutoIndexes.new(@connection)
57
- @schema_indexes ||= SchemaIndexes.new(@connection)
58
- @node_traversal ||= NodeTraversal.new(@connection)
59
- @node_paths ||= NodePaths.new(@connection)
60
- @node_labels ||= NodeLabels.new(@connection)
61
-
62
- @relationships ||= Relationships.new(@connection)
63
- @relationship_properties ||= RelationshipProperties.new(@connection)
64
- @relationship_indexes ||= RelationshipIndexes.new(@connection)
65
- @relationship_auto_indexes ||= RelationshipAutoIndexes.new(@connection)
66
- @relationship_types ||= RelationshipTypes.new(@connection)
67
-
68
- @cypher ||= Cypher.new(@connection)
69
- @gremlin ||= Gremlin.new(@connection)
70
- @extensions ||= Extensions.new(@connection)
71
- @batch ||= Batch.new(@connection)
72
- @clean ||= Clean.new(@connection)
73
- @transactions ||= Transactions.new(@connection)
74
- @spatial ||= Spatial.new(@connection)
75
- @constraints ||= Constraints.new(@connection)
76
- end
77
-
78
- # meta-data
79
-
80
- def list_relationship_types
81
- @relationship_types.list
82
- end
83
-
84
- # labels
85
-
86
- def list_labels
87
- @node_labels.list
88
- end
89
-
90
- def add_label(id, label)
91
- @node_labels.add(id, label)
92
- end
93
-
94
- def set_label(id, label)
95
- @node_labels.set(id, label)
96
- end
97
-
98
- def delete_label(id, label)
99
- @node_labels.delete(id, label)
100
- end
101
-
102
- def get_node_labels(id)
103
- @node_labels.get(id)
104
- end
105
-
106
- def get_nodes_labeled(label)
107
- @node_labels.get_nodes(label)
108
- end
109
-
110
- def find_nodes_labeled(label, hash)
111
- @node_labels.find_nodes(label, hash)
112
- end
113
-
114
- # schema indexes
115
-
116
- def get_schema_index(label)
117
- @schema_indexes.list(label)
118
- end
119
-
120
- def create_schema_index(label, properties)
121
- @schema_indexes.create(label, properties)
122
- end
123
-
124
- def delete_schema_index(label, property)
125
- @schema_indexes.drop(label, property)
126
- end
127
-
128
- # constraints
129
-
130
- def get_constraints(label=nil)
131
- label.nil? ? @constraints.list : @constraints.get(label)
132
- end
133
-
134
- def drop_constraint(label, property)
135
- @constraints.drop(label, property)
136
- end
137
-
138
- def get_uniqueness(label)
139
- @constraints.get_uniqueness(label)
140
- end
141
-
142
- def get_unique_constraint(label, property)
143
- @constraints.get_unique(label, property)
144
- end
145
-
146
- def create_unique_constraint(label, property)
147
- @constraints.create_unique(label, property)
148
- end
67
+ alias_method :list_indexes, :list_node_indexes
68
+ alias_method :add_to_index, :add_node_to_index
69
+ alias_method :remove_from_index, :remove_node_from_index
70
+ alias_method :get_index, :get_node_index
149
71
 
150
- # transactions
151
-
152
- def begin_transaction(statements=nil)
153
- @transactions.begin(statements)
154
- end
155
-
156
- def in_transaction(tx, statements)
157
- @transactions.add(tx, statements)
158
- end
159
-
160
- def keep_transaction(tx)
161
- @transactions.add(tx)
162
- end
163
-
164
- def commit_transaction(tx, statements=[])
165
- if (tx.is_a?(Hash) || tx.is_a?(Integer))
166
- @transactions.commit(tx, statements)
167
- else
168
- @transactions.begin(tx, "/commit")
169
- end
170
- end
171
-
172
- def rollback_transaction(tx)
173
- @transactions.rollback(tx)
174
- end
175
-
176
- # nodes
177
-
178
- def get_root
179
- @nodes.root
180
- end
181
-
182
- def get_node(id)
183
- @nodes.get(id)
184
- end
185
-
186
- def get_nodes(*args)
187
- @nodes.get_each(*args)
188
- end
189
-
190
- def create_node(*args)
191
- @nodes.create(*args)
192
- end
193
-
194
- def create_nodes(args)
195
- @nodes.create_multiple(args)
196
- end
197
-
198
- def create_nodes_threaded(args)
199
- @nodes.create_multiple_threaded(args)
200
- end
201
-
202
- def delete_node(id)
203
- @nodes.delete(id)
204
- end
205
-
206
72
  def delete_node!(id)
207
73
  relationships = get_node_relationships(get_id(id))
208
74
  relationships.each do |relationship|
@@ -219,324 +85,15 @@ module Neography
219
85
  # get("/nodes/")
220
86
  # end
221
87
 
222
- # node properties
223
-
224
- def get_node_properties(id, *properties)
225
- @node_properties.get(id, *properties.flatten)
226
- end
227
-
228
- def set_node_properties(id, properties)
229
- @node_properties.set(id, properties)
230
- end
231
-
232
- def reset_node_properties(id, properties)
233
- @node_properties.reset(id, properties)
234
- end
235
-
236
- def remove_node_properties(id, *properties)
237
- @node_properties.remove(id, *properties.flatten)
238
- end
239
-
240
88
  # relationships
241
89
 
242
- def get_relationship(id)
243
- @relationships.get(id)
244
- end
245
-
246
- def delete_relationship(id)
247
- @relationships.delete(id)
248
- end
249
-
250
90
  def get_relationship_start_node(rel)
251
91
  get_node(rel["start"])
252
92
  end
253
93
 
254
94
  def get_relationship_end_node(rel)
255
95
  get_node(rel["end"])
256
- end
257
-
258
- # relationship properties
259
-
260
- def get_relationship_properties(id, *properties)
261
- @relationship_properties.get(id, *properties.flatten)
262
- end
263
-
264
- def set_relationship_properties(id, properties)
265
- @relationship_properties.set(id, properties)
266
- end
267
-
268
- def reset_relationship_properties(id, properties)
269
- @relationship_properties.reset(id, properties)
270
- end
271
-
272
- def remove_relationship_properties(id, *properties)
273
- @relationship_properties.remove(id, *properties.flatten)
274
- end
275
-
276
- # node relationships
277
-
278
- def get_node_relationships(id, dir = nil, types = nil)
279
- @node_relationships.get(id, dir, types)
280
- end
281
-
282
- def get_node_relationships_to(id, other_id, dir = "all", types = nil)
283
- @other_node_relationships.get(id, other_id, dir, Array(types || [nil]))
284
- end
285
-
286
- def create_relationship(type, from, to, props = nil)
287
- @node_relationships.create(type, from, to, props)
288
- end
289
-
290
- # node indexes
291
-
292
- def list_node_indexes
293
- @node_indexes.list
294
- end
295
- alias_method :list_indexes, :list_node_indexes
296
-
297
- def create_node_index(name, type = "exact", provider = "lucene", extra_config = nil)
298
- @node_indexes.create(name, type, provider, extra_config)
299
- end
300
-
301
- def create_node_auto_index(type = "exact", provider = "lucene")
302
- @node_indexes.create_auto(type, provider)
303
- end
304
-
305
- def create_unique_node(index, key, value, props={})
306
- @node_indexes.create_unique(index, key, value, props)
307
- end
308
-
309
- def add_node_to_index(index, key, value, id, unique=false)
310
- @node_indexes.add(index, key, value, id, unique)
311
- end
312
- alias_method :add_to_index, :add_node_to_index
313
-
314
- def remove_node_from_index(index, id_or_key, id_or_value = nil, id = nil)
315
- @node_indexes.remove(index, id_or_key, id_or_value, id)
316
- end
317
- alias_method :remove_from_index, :remove_node_from_index
318
-
319
- def get_node_index(index, key, value)
320
- @node_indexes.get(index, key, value)
321
- end
322
- alias_method :get_index, :get_node_index
323
-
324
- def find_node_index(index, key_or_query, value = nil)
325
- @node_indexes.find(index, key_or_query, value)
326
- end
327
-
328
- def drop_node_index(index)
329
- @node_indexes.drop(index)
330
- end
331
-
332
- # auto node indexes
333
-
334
- def get_node_auto_index(key, value)
335
- @node_auto_indexes.get(key, value)
336
- end
337
-
338
- def find_node_auto_index(key_or_query, value = nil)
339
- @node_auto_indexes.find_or_query(key_or_query, value)
340
- end
341
-
342
- def get_node_auto_index_status
343
- @node_auto_indexes.status
344
- end
345
-
346
- def set_node_auto_index_status(change_to = true)
347
- @node_auto_indexes.status = change_to
348
- end
349
-
350
- def get_node_auto_index_properties
351
- @node_auto_indexes.properties
352
- end
353
-
354
- def add_node_auto_index_property(property)
355
- @node_auto_indexes.add_property(property)
356
- end
357
-
358
- def remove_node_auto_index_property(property)
359
- @node_auto_indexes.remove_property(property)
360
- end
361
-
362
- # relationship indexes
363
-
364
- def list_relationship_indexes
365
- @relationship_indexes.list
366
- end
367
-
368
- def create_relationship_index(name, type = "exact", provider = "lucene")
369
- @relationship_indexes.create(name, type, provider)
370
- end
371
-
372
- def create_relationship_auto_index(type = "exact", provider = "lucene")
373
- @relationship_indexes.create_auto(type, provider)
374
- end
375
-
376
- def create_unique_relationship(index, key, value, type, from, to, props = nil)
377
- @relationship_indexes.create_unique(index, key, value, type, from, to, props)
378
- end
379
-
380
- def add_relationship_to_index(index, key, value, id)
381
- @relationship_indexes.add(index, key, value, id)
382
- end
383
-
384
- def remove_relationship_from_index(index, id_or_key, id_or_value = nil, id = nil)
385
- @relationship_indexes.remove(index, id_or_key, id_or_value, id)
386
- end
387
-
388
- def get_relationship_index(index, key, value)
389
- @relationship_indexes.get(index, key, value)
390
- end
391
-
392
- def find_relationship_index(index, key_or_query, value = nil)
393
- @relationship_indexes.find(index, key_or_query, value)
394
- end
395
-
396
- def drop_relationship_index(index)
397
- @relationship_indexes.drop(index)
398
- end
399
-
400
- # relationship auto indexes
401
-
402
- def get_relationship_auto_index(key, value)
403
- @relationship_auto_indexes.get(key, value)
404
- end
405
-
406
- def find_relationship_auto_index(key_or_query, value = nil)
407
- @relationship_auto_indexes.find_or_query(key_or_query, value)
408
- end
409
-
410
- def get_relationship_auto_index_status
411
- @relationship_auto_indexes.status
412
- end
413
-
414
- def set_relationship_auto_index_status(change_to = true)
415
- @relationship_auto_indexes.status = change_to
416
- end
417
-
418
- def get_relationship_auto_index_properties
419
- @relationship_auto_indexes.properties
420
- end
421
-
422
- def add_relationship_auto_index_property(property)
423
- @relationship_auto_indexes.add_property(property)
424
- end
425
-
426
- def remove_relationship_auto_index_property(property)
427
- @relationship_auto_indexes.remove_property(property)
428
- end
429
-
430
- # traversal
431
-
432
- def traverse(id, return_type, description)
433
- @node_traversal.traverse(id, return_type, description)
434
- end
435
-
436
- # paths
437
-
438
- def get_path(from, to, relationships, depth = 1, algorithm = "shortestPath")
439
- @node_paths.get(from, to, relationships, depth, algorithm)
440
- end
441
-
442
- def get_paths(from, to, relationships, depth = 1, algorithm = "allPaths")
443
- @node_paths.get_all(from, to, relationships, depth, algorithm)
444
- end
445
-
446
- def get_shortest_weighted_path(from, to, relationships, weight_attr = "weight", depth = 1, algorithm = "dijkstra")
447
- @node_paths.shortest_weighted(from, to, relationships, weight_attr, depth, algorithm)
448
- end
449
-
450
- # cypher query
451
-
452
- def execute_query(query, params = {}, cypher_options = nil)
453
- @cypher.query(query, params, cypher_options)
454
- end
455
-
456
- # gremlin script
457
-
458
- def execute_script(script, params = {})
459
- @gremlin.execute(script, params)
460
- end
461
-
462
- # unmanaged extensions
463
-
464
- def post_extension(path, params = {}, headers = nil)
465
- @extensions.post(path, params, headers)
466
- end
467
-
468
- def get_extension(path)
469
- @extensions.get(path)
470
- end
471
-
472
- # batch
473
-
474
- def batch(*args)
475
- @batch.execute(*args)
476
- end
477
-
478
- def batch_not_streaming(*args)
479
- @batch.not_streaming(*args)
480
- end
481
-
482
- # spatial
483
-
484
- def get_spatial
485
- @spatial.index
486
- end
487
-
488
- def add_point_layer(layer, lat = nil, lon = nil)
489
- @spatial.add_point_layer(layer, lat, lon)
490
- end
491
-
492
- def add_editable_layer(layer, format, node_property_name)
493
- @spatial.add_editable_layer(layer, format, node_property_name)
494
- end
495
-
496
- def get_layer(layer)
497
- @spatial.get_layer(layer)
498
- end
499
-
500
- def add_geometry_to_layer(layer, geometry)
501
- @spatial.add_geometry_to_layer(layer, geometry)
502
- end
503
-
504
- def edit_geometry_from_layer(layer, geometry, node)
505
- @spatial.edit_geometry_from_layer(layer, geometry, node)
506
- end
507
-
508
- def add_node_to_layer(layer, node)
509
- @spatial.add_node_to_layer(layer, node)
510
- end
511
-
512
- def find_geometries_in_bbox(layer, minx, maxx, miny, maxy)
513
- @spatial.find_geometries_in_bbox(layer, minx, maxx, miny, maxy)
514
- end
515
-
516
- def find_geometries_within_distance(layer, pointx, pointy, distance)
517
- @spatial.find_geometries_within_distance(layer, pointx, pointy, distance)
518
- end
96
+ end
519
97
 
520
- def create_spatial_index(name, type = nil, lat = nil, lon = nil)
521
- @spatial.create_spatial_index(name, type, lat, lon)
522
- end
523
-
524
- def add_node_to_spatial_index(index, id)
525
- @spatial.add_node_to_spatial_index(index, id)
526
- end
527
-
528
- # clean database
529
-
530
- # For testing (use a separate neo4j instance)
531
- # call this before each test or spec
532
- def clean_database(sanity_check = "not_really")
533
- if sanity_check == "yes_i_really_want_to_clean_the_database"
534
- @clean.execute
535
- true
536
- else
537
- false
538
- end
539
- end
540
-
541
98
  end
542
99
  end