neography 1.3.14 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neography/rest.rb +29 -472
- data/lib/neography/rest/batch.rb +80 -87
- data/lib/neography/rest/clean.rb +8 -10
- data/lib/neography/rest/constraints.rb +15 -25
- data/lib/neography/rest/cypher.rb +2 -6
- data/lib/neography/rest/extensions.rb +4 -8
- data/lib/neography/rest/gremlin.rb +2 -6
- data/lib/neography/rest/helpers.rb +58 -0
- data/lib/neography/rest/node_auto_indexes.rb +54 -8
- data/lib/neography/rest/node_indexes.rb +92 -17
- data/lib/neography/rest/node_labels.rb +15 -26
- data/lib/neography/rest/node_paths.rb +8 -16
- data/lib/neography/rest/node_properties.rb +45 -4
- data/lib/neography/rest/node_relationships.rb +8 -17
- data/lib/neography/rest/node_traversal.rb +7 -63
- data/lib/neography/rest/nodes.rb +21 -29
- data/lib/neography/rest/other_node_relationships.rb +6 -13
- data/lib/neography/rest/relationship_auto_indexes.rb +54 -8
- data/lib/neography/rest/relationship_indexes.rb +104 -14
- data/lib/neography/rest/relationship_properties.rb +45 -4
- data/lib/neography/rest/relationship_types.rb +4 -11
- data/lib/neography/rest/relationships.rb +6 -13
- data/lib/neography/rest/schema_indexes.rb +8 -16
- data/lib/neography/rest/spatial.rb +16 -33
- data/lib/neography/rest/transactions.rb +25 -26
- data/lib/neography/tasks.rb +2 -2
- data/lib/neography/version.rb +1 -1
- data/spec/unit/rest/batch_spec.rb +49 -50
- data/spec/unit/rest/clean_spec.rb +3 -4
- data/spec/unit/rest/constraints_spec.rb +12 -13
- data/spec/unit/rest/cypher_spec.rb +3 -4
- data/spec/unit/rest/extensions_spec.rb +5 -6
- data/spec/unit/rest/gremlin_spec.rb +5 -6
- data/spec/unit/rest/helpers_spec.rb +124 -0
- data/spec/unit/rest/labels_spec.rb +21 -22
- data/spec/unit/rest/node_auto_indexes_spec.rb +23 -24
- data/spec/unit/rest/node_indexes_spec.rb +42 -43
- data/spec/unit/rest/node_paths_spec.rb +10 -13
- data/spec/unit/rest/node_properties_spec.rb +22 -23
- data/spec/unit/rest/node_relationships_spec.rb +18 -39
- data/spec/unit/rest/node_traversal_spec.rb +4 -97
- data/spec/unit/rest/nodes_spec.rb +47 -48
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +23 -24
- data/spec/unit/rest/relationship_indexes_spec.rb +42 -43
- data/spec/unit/rest/relationship_properties_spec.rb +22 -23
- data/spec/unit/rest/relationship_types_spec.rb +3 -4
- data/spec/unit/rest/relationships_spec.rb +5 -6
- data/spec/unit/rest/schema_index_spec.rb +7 -8
- data/spec/unit/rest/transactions_spec.rb +10 -11
- metadata +27 -31
- data/lib/neography/rest/auto_indexes.rb +0 -64
- data/lib/neography/rest/indexes.rb +0 -102
- data/lib/neography/rest/paths.rb +0 -46
- data/lib/neography/rest/properties.rb +0 -56
- data/spec/unit/rest/paths_spec.rb +0 -69
data/lib/neography/rest/batch.rb
CHANGED
@@ -1,22 +1,15 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module Batch
|
5
4
|
include Neography::Rest::Helpers
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(connection)
|
10
|
-
@connection ||= connection
|
11
|
-
end
|
12
|
-
|
13
|
-
def execute(*args)
|
14
|
-
batch(*args)
|
5
|
+
|
6
|
+
def batch(*args)
|
7
|
+
do_batch(*args)
|
15
8
|
end
|
16
9
|
|
17
10
|
private
|
18
11
|
|
19
|
-
def
|
12
|
+
def do_batch(*args)
|
20
13
|
batch = []
|
21
14
|
Array(args).each_with_index do |c, i|
|
22
15
|
batch << {:id => i }.merge(get_batch(c))
|
@@ -25,54 +18,54 @@ module Neography
|
|
25
18
|
:body => batch.to_json,
|
26
19
|
:headers => json_content_type
|
27
20
|
}
|
28
|
-
@connection.post(
|
21
|
+
@connection.post("/batch", options)
|
29
22
|
end
|
30
23
|
|
31
24
|
def get_batch(args)
|
32
|
-
if
|
33
|
-
send(args[0].to_sym, *args[1..-1])
|
25
|
+
if args[0].class == Symbol
|
26
|
+
send(("batch_" + args[0].to_s).to_sym, *args[1..-1])
|
34
27
|
else
|
35
|
-
raise "Unknown option #{args[0]}"
|
28
|
+
raise "Unknown option #{args[0]} - #{args}"
|
36
29
|
end
|
37
30
|
end
|
38
31
|
|
39
32
|
# Nodes
|
40
33
|
|
41
|
-
def
|
42
|
-
get
|
34
|
+
def batch_get_node(id)
|
35
|
+
get "/node/%{id}" % {:id => get_id(id)}
|
43
36
|
end
|
44
37
|
|
45
|
-
def
|
46
|
-
delete
|
38
|
+
def batch_delete_node(id)
|
39
|
+
delete "/node/%{id}" % {:id => get_id(id)}
|
47
40
|
end
|
48
41
|
|
49
|
-
def
|
50
|
-
post
|
42
|
+
def batch_create_node(body)
|
43
|
+
post "/node" do
|
51
44
|
body
|
52
45
|
end
|
53
46
|
end
|
54
47
|
|
55
48
|
# NodeIndexes
|
56
49
|
|
57
|
-
def
|
50
|
+
def batch_create_node_index(name, type = "exact", provider = "lucene", extra_config = nil)
|
58
51
|
config = {
|
59
52
|
:type => type,
|
60
53
|
:provider => provider
|
61
54
|
}
|
62
55
|
config.merge!(extra_config) unless extra_config.nil?
|
63
|
-
post
|
56
|
+
post "/index/node" do
|
64
57
|
{ :name => name,
|
65
58
|
:config => config
|
66
59
|
}
|
67
60
|
end
|
68
61
|
end
|
69
62
|
|
70
|
-
def
|
71
|
-
delete
|
63
|
+
def batch_drop_node_index(index)
|
64
|
+
delete "/index/node/%{index}?unique" % {:index => index}
|
72
65
|
end
|
73
66
|
|
74
|
-
def
|
75
|
-
post
|
67
|
+
def batch_create_unique_node(index, key, value, properties)
|
68
|
+
post "/index/node/%{index}?unique" % {:index => index} do
|
76
69
|
{
|
77
70
|
:key => key,
|
78
71
|
:value => value,
|
@@ -81,8 +74,8 @@ module Neography
|
|
81
74
|
end
|
82
75
|
end
|
83
76
|
|
84
|
-
def
|
85
|
-
path = unique ?
|
77
|
+
def batch_add_node_to_index(index, key, value, id, unique = false)
|
78
|
+
path = unique ? "/index/node/%{index}?unique" % {:index => index} : "/index/node/%{index}" % {:index => index}
|
86
79
|
post path do
|
87
80
|
{
|
88
81
|
:uri => build_node_uri(id),
|
@@ -92,35 +85,35 @@ module Neography
|
|
92
85
|
end
|
93
86
|
end
|
94
87
|
|
95
|
-
def
|
96
|
-
get
|
88
|
+
def batch_get_node_index(index, key, value)
|
89
|
+
get "/index/node/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}
|
97
90
|
end
|
98
91
|
|
99
|
-
def
|
100
|
-
delete remove_from_index_path(
|
92
|
+
def batch_remove_node_from_index(index, key_or_id, value_or_id = nil, id = nil)
|
93
|
+
delete remove_from_index_path("node", index, key_or_id, value_or_id, id)
|
101
94
|
end
|
102
95
|
|
103
96
|
# NodeProperties
|
104
97
|
|
105
|
-
def
|
106
|
-
put
|
98
|
+
def batch_set_node_property(id, property)
|
99
|
+
put "/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property.keys.first} do
|
107
100
|
property.values.first
|
108
101
|
end
|
109
102
|
end
|
110
103
|
|
111
|
-
def
|
112
|
-
put
|
104
|
+
def batch_reset_node_properties(id, body)
|
105
|
+
put "/node/%{id}/properties" % {:id => get_id(id)} do
|
113
106
|
body
|
114
107
|
end
|
115
108
|
end
|
116
109
|
|
117
|
-
def
|
118
|
-
delete
|
110
|
+
def batch_remove_node_property(id, property)
|
111
|
+
delete "/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property}
|
119
112
|
end
|
120
113
|
|
121
114
|
# NodeLabel
|
122
115
|
|
123
|
-
def
|
116
|
+
def batch_add_label(id, body)
|
124
117
|
post build_node_uri(id) + "/labels" do
|
125
118
|
body
|
126
119
|
end
|
@@ -128,25 +121,25 @@ module Neography
|
|
128
121
|
|
129
122
|
# NodeRelationships
|
130
123
|
|
131
|
-
def
|
124
|
+
def batch_get_node_relationships(id, direction = nil, types = nil)
|
132
125
|
if types.nil?
|
133
|
-
get
|
126
|
+
get "/node/%{id}/relationships/%{direction}" % {:id => get_id(id), :direction => direction || 'all'}
|
134
127
|
else
|
135
|
-
get
|
128
|
+
get "/node/%{id}/relationships/%{direction}/%{types}" % {:id => get_id(id), :direction => direction, :types => Array(types).join('&')}
|
136
129
|
end
|
137
130
|
end
|
138
131
|
|
139
132
|
# Relationships
|
140
133
|
|
141
|
-
def
|
142
|
-
get
|
134
|
+
def batch_get_relationship(id)
|
135
|
+
get "/relationship/%{id}" % {:id => get_id(id)}
|
143
136
|
end
|
144
137
|
|
145
|
-
def
|
146
|
-
delete
|
138
|
+
def batch_delete_relationship(id)
|
139
|
+
delete "/relationship/%{id}" % {:id => get_id(id)}
|
147
140
|
end
|
148
141
|
|
149
|
-
def
|
142
|
+
def batch_create_relationship(type, from, to, data = nil)
|
150
143
|
post build_node_uri(from) + "/relationships" do
|
151
144
|
{
|
152
145
|
:to => build_node_uri(to),
|
@@ -158,8 +151,8 @@ module Neography
|
|
158
151
|
|
159
152
|
# RelationshipIndexes
|
160
153
|
|
161
|
-
def
|
162
|
-
post
|
154
|
+
def batch_create_unique_relationship(index, key, value, type, from, to, props = nil)
|
155
|
+
post "/index/relationship/%{index}?unique" % {:index => index} do
|
163
156
|
{
|
164
157
|
:key => key,
|
165
158
|
:value => value,
|
@@ -171,8 +164,8 @@ module Neography
|
|
171
164
|
end
|
172
165
|
end
|
173
166
|
|
174
|
-
def
|
175
|
-
post
|
167
|
+
def batch_add_relationship_to_index(index, key, value, id)
|
168
|
+
post "/index/relationship/%{index}" % {:index => index} do
|
176
169
|
{
|
177
170
|
:uri => build_relationship_uri(id),
|
178
171
|
:key => key,
|
@@ -181,23 +174,23 @@ module Neography
|
|
181
174
|
end
|
182
175
|
end
|
183
176
|
|
184
|
-
def
|
185
|
-
get
|
177
|
+
def batch_get_relationship_index(index, key, value)
|
178
|
+
get "/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}
|
186
179
|
end
|
187
180
|
|
188
|
-
def
|
189
|
-
delete remove_from_index_path(
|
181
|
+
def batch_remove_relationship_from_index(index, key_or_id, value_or_id = nil, id = nil)
|
182
|
+
delete remove_from_index_path("relationship", index, key_or_id, value_or_id, id)
|
190
183
|
end
|
191
184
|
|
192
185
|
# RelationshipProperties
|
193
186
|
|
194
|
-
def
|
195
|
-
put
|
187
|
+
def batch_set_relationship_property(id, property)
|
188
|
+
put "/relationship/%{id}/properties/%{property}" % {:id => get_id(id), :property => property.keys.first} do
|
196
189
|
property.values.first
|
197
190
|
end
|
198
191
|
end
|
199
192
|
|
200
|
-
def
|
193
|
+
def batch_reset_relationship_properties(id, body)
|
201
194
|
put build_relationship_uri(id) + "/properties" do
|
202
195
|
body
|
203
196
|
end
|
@@ -205,7 +198,7 @@ module Neography
|
|
205
198
|
|
206
199
|
# Cypher
|
207
200
|
|
208
|
-
def
|
201
|
+
def batch_execute_query(query, params = nil)
|
209
202
|
request = post @connection.cypher_path do
|
210
203
|
{
|
211
204
|
:query => query
|
@@ -219,7 +212,7 @@ module Neography
|
|
219
212
|
|
220
213
|
# Gremlin
|
221
214
|
|
222
|
-
def
|
215
|
+
def batch_execute_script(script, params = nil)
|
223
216
|
post @connection.gremlin_path do
|
224
217
|
{
|
225
218
|
:script => script,
|
@@ -232,22 +225,22 @@ module Neography
|
|
232
225
|
|
233
226
|
def remove_from_index_path(klass, index, key_or_id, value_or_id = nil, id = nil)
|
234
227
|
if id
|
235
|
-
klass
|
228
|
+
"/index/#{klass}/%{index}/%{key}/%{value}/%{id}" % {:index => index, :key => key_or_id, :value => value_or_id, :id => get_id(id)}
|
236
229
|
elsif value_or_id
|
237
|
-
klass
|
230
|
+
"/index/#{klass}/%{index}/%{key}/%{id}" % {:index => index, :key => key_or_id, :id => get_id(value_or_id)}
|
238
231
|
else
|
239
|
-
klass
|
232
|
+
"/index/#{klass}/%{index}/%{id}" % {:index => index, :id => get_id(key_or_id)}
|
240
233
|
end
|
241
234
|
end
|
242
235
|
|
243
236
|
# Spatial
|
244
237
|
|
245
|
-
def
|
246
|
-
get
|
238
|
+
def batch_get_spatial
|
239
|
+
get "/ext/SpatialPlugin"
|
247
240
|
end
|
248
241
|
|
249
|
-
def
|
250
|
-
post
|
242
|
+
def batch_add_point_layer(layer, lat = nil, lon = nil)
|
243
|
+
post "/ext/SpatialPlugin/graphdb/addSimplePointLayer" do
|
251
244
|
{
|
252
245
|
:layer => layer,
|
253
246
|
:lat => lat || "lat",
|
@@ -256,8 +249,8 @@ module Neography
|
|
256
249
|
end
|
257
250
|
end
|
258
251
|
|
259
|
-
def
|
260
|
-
post
|
252
|
+
def batch_add_editable_layer(layer, format = "WKT", node_property_name = "wkt")
|
253
|
+
post "/ext/SpatialPlugin/graphdb/addEditableLayer" do
|
261
254
|
{
|
262
255
|
:layer => layer,
|
263
256
|
:format => format,
|
@@ -266,16 +259,16 @@ module Neography
|
|
266
259
|
end
|
267
260
|
end
|
268
261
|
|
269
|
-
def
|
270
|
-
post
|
262
|
+
def batch_get_layer(layer)
|
263
|
+
post "/ext/SpatialPlugin/graphdb/getLayer" do
|
271
264
|
{
|
272
265
|
:layer => layer
|
273
266
|
}
|
274
267
|
end
|
275
268
|
end
|
276
269
|
|
277
|
-
def
|
278
|
-
post
|
270
|
+
def batch_add_geometry_to_layer(layer, geometry)
|
271
|
+
post "/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer" do
|
279
272
|
{
|
280
273
|
:layer => layer,
|
281
274
|
:geometry => geometry
|
@@ -283,8 +276,8 @@ module Neography
|
|
283
276
|
end
|
284
277
|
end
|
285
278
|
|
286
|
-
def
|
287
|
-
post
|
279
|
+
def batch_edit_geometry_from_layer(layer, geometry, node)
|
280
|
+
post "/ext/SpatialPlugin/graphdb/updateGeometryFromWKT" do
|
288
281
|
{
|
289
282
|
:layer => layer,
|
290
283
|
:geometry => geometry,
|
@@ -293,8 +286,8 @@ module Neography
|
|
293
286
|
end
|
294
287
|
end
|
295
288
|
|
296
|
-
def
|
297
|
-
post
|
289
|
+
def batch_add_node_to_layer(layer, node)
|
290
|
+
post "/ext/SpatialPlugin/graphdb/addNodeToLayer" do
|
298
291
|
{
|
299
292
|
:layer => layer,
|
300
293
|
:node => get_id(node)
|
@@ -302,8 +295,8 @@ module Neography
|
|
302
295
|
end
|
303
296
|
end
|
304
297
|
|
305
|
-
def
|
306
|
-
post
|
298
|
+
def batch_find_geometries_in_bbox(layer, minx, maxx, miny, maxy)
|
299
|
+
post "/ext/SpatialPlugin/graphdb/findGeometriesInBBox" do
|
307
300
|
{
|
308
301
|
:layer => layer,
|
309
302
|
:minx => minx,
|
@@ -314,8 +307,8 @@ module Neography
|
|
314
307
|
end
|
315
308
|
end
|
316
309
|
|
317
|
-
def
|
318
|
-
post
|
310
|
+
def batch_find_geometries_within_distance(layer, pointx, pointy, distance)
|
311
|
+
post "/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance" do
|
319
312
|
{
|
320
313
|
:layer => layer,
|
321
314
|
:pointX => pointx,
|
@@ -325,8 +318,8 @@ module Neography
|
|
325
318
|
end
|
326
319
|
end
|
327
320
|
|
328
|
-
def
|
329
|
-
post
|
321
|
+
def batch_create_spatial_index(name, type, lat, lon)
|
322
|
+
post "/index/node" do
|
330
323
|
{
|
331
324
|
:name => name,
|
332
325
|
:config => {
|
@@ -339,8 +332,8 @@ module Neography
|
|
339
332
|
end
|
340
333
|
end
|
341
334
|
|
342
|
-
def
|
343
|
-
post
|
335
|
+
def batch_add_node_to_spatial_index(index, id)
|
336
|
+
post "/index/node/%{index}" % {:index => index} do
|
344
337
|
{
|
345
338
|
:uri => build_node_uri(id),
|
346
339
|
:key => "k",
|
data/lib/neography/rest/clean.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module Clean
|
5
4
|
include Neography::Rest::Helpers
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@connection.delete(clean_path)
|
6
|
+
def clean_database(sanity_check = "not_really")
|
7
|
+
if sanity_check == "yes_i_really_want_to_clean_the_database"
|
8
|
+
@connection.delete("/cleandb/secret-key")
|
9
|
+
true
|
10
|
+
else
|
11
|
+
false
|
12
|
+
end
|
15
13
|
end
|
16
14
|
|
17
15
|
end
|
@@ -1,46 +1,36 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module Constraints
|
5
4
|
include Neography::Rest::Helpers
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
add_path :uniqueness, "/schema/constraint/:label/uniqueness/"
|
10
|
-
add_path :unique, "/schema/constraint/:label/uniqueness/:property"
|
11
|
-
|
12
|
-
def initialize(connection)
|
13
|
-
@connection ||= connection
|
14
|
-
end
|
15
|
-
|
16
|
-
def drop(label, property)
|
17
|
-
@connection.delete(unique_path(:label => label, :property => property))
|
18
|
-
end
|
19
|
-
|
20
|
-
def list
|
21
|
-
@connection.get(base_path)
|
5
|
+
|
6
|
+
def drop_constraint(label, property)
|
7
|
+
@connection.delete("/schema/constraint/%{label}/uniqueness/%{property}" % {:label => label, :property => property})
|
22
8
|
end
|
23
9
|
|
24
|
-
def
|
25
|
-
|
10
|
+
def get_constraints(label=nil)
|
11
|
+
#if label.nil?
|
12
|
+
# @connection.get(base_path)
|
13
|
+
#else
|
14
|
+
@connection.get("/schema/constraint/%{label}" % {:label => label})
|
15
|
+
#end
|
26
16
|
end
|
27
17
|
|
28
18
|
def get_uniqueness(label)
|
29
|
-
@connection.get(
|
19
|
+
@connection.get("/schema/constraint/%{label}/uniqueness/" % {:label => label})
|
30
20
|
end
|
31
21
|
|
32
|
-
def
|
33
|
-
@connection.get(
|
22
|
+
def get_unique_constraint(label, property)
|
23
|
+
@connection.get("/schema/constraint/%{label}/uniqueness/%{property}" % {:label => label, :property => property})
|
34
24
|
end
|
35
25
|
|
36
|
-
def
|
26
|
+
def create_unique_constraint(label, property)
|
37
27
|
options = {
|
38
28
|
:body => {
|
39
29
|
:property_keys => [property]
|
40
30
|
}.to_json,
|
41
31
|
:headers => json_content_type
|
42
32
|
}
|
43
|
-
@connection.post(
|
33
|
+
@connection.post("/schema/constraint/%{label}/uniqueness/" % {:label => label}, options)
|
44
34
|
end
|
45
35
|
|
46
36
|
end
|