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
@@ -1,18 +1,9 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module NodeRelationships
|
5
4
|
include Neography::Rest::Helpers
|
6
|
-
|
7
|
-
|
8
|
-
add_path :direction, "/node/:id/relationships/:direction"
|
9
|
-
add_path :type, "/node/:id/relationships/:direction/:types"
|
10
|
-
|
11
|
-
def initialize(connection)
|
12
|
-
@connection ||= connection
|
13
|
-
end
|
14
|
-
|
15
|
-
def create(type, from, to, properties = nil)
|
5
|
+
|
6
|
+
def create_relationship(type, from, to, properties = nil)
|
16
7
|
options = {
|
17
8
|
:body => {
|
18
9
|
:to => @connection.configuration + "/node/#{get_id(to)}",
|
@@ -21,16 +12,16 @@ module Neography
|
|
21
12
|
}.to_json,
|
22
13
|
:headers => json_content_type }
|
23
14
|
|
24
|
-
@connection.post(
|
15
|
+
@connection.post("/node/%{id}/relationships" % {:id => get_id(from)}, options)
|
25
16
|
end
|
26
|
-
|
27
|
-
def
|
17
|
+
|
18
|
+
def get_node_relationships(id, direction = nil, types = nil)
|
28
19
|
direction = parse_direction(direction)
|
29
20
|
|
30
21
|
if types.nil?
|
31
|
-
node_relationships = @connection.get(
|
22
|
+
node_relationships = @connection.get("/node/%{id}/relationships/%{direction}" % {:id => get_id(id), :direction => direction}) || []
|
32
23
|
else
|
33
|
-
node_relationships = @connection.get(
|
24
|
+
node_relationships = @connection.get("/node/%{id}/relationships/%{direction}/%{types}" % {:id => get_id(id), :direction => direction, :types => encode(Array(types).join('&'))}) || []
|
34
25
|
end
|
35
26
|
|
36
27
|
return [] if node_relationships.empty?
|
@@ -1,79 +1,23 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module NodeTraversal
|
5
4
|
include Neography::Rest::Helpers
|
6
|
-
|
7
|
-
add_path :traversal, "/node/:id/traverse/:type"
|
8
|
-
|
9
|
-
def initialize(connection)
|
10
|
-
@connection ||= connection
|
11
|
-
end
|
12
|
-
|
5
|
+
|
13
6
|
def traverse(id, return_type, description)
|
14
7
|
options = { :body => {
|
15
|
-
"order" =>
|
16
|
-
"uniqueness" =>
|
8
|
+
"order" => parse_order(description["order"]),
|
9
|
+
"uniqueness" => parse_uniqueness(description["uniqueness"]),
|
17
10
|
"relationships" => description["relationships"],
|
18
11
|
"prune_evaluator" => description["prune evaluator"],
|
19
12
|
"return_filter" => description["return filter"],
|
20
|
-
"max_depth" =>
|
13
|
+
"max_depth" => parse_depth(description["depth"])
|
21
14
|
}.to_json,
|
22
15
|
:headers => json_content_type
|
23
16
|
}
|
24
17
|
|
25
|
-
type =
|
26
|
-
|
27
|
-
@connection.post(traversal_path(:id => get_id(id), :type => type), options) || []
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def get_order(order)
|
33
|
-
case order
|
34
|
-
when :breadth, "breadth", "breadth first", "breadthFirst", :wide, "wide"
|
35
|
-
"breadth first"
|
36
|
-
else
|
37
|
-
"depth first"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def get_uniqueness(uniqueness)
|
42
|
-
case uniqueness
|
43
|
-
when :nodeglobal, "node global", "nodeglobal", "node_global"
|
44
|
-
"node global"
|
45
|
-
when :nodepath, "node path", "nodepath", "node_path"
|
46
|
-
"node path"
|
47
|
-
when :noderecent, "node recent", "noderecent", "node_recent"
|
48
|
-
"node recent"
|
49
|
-
when :relationshipglobal, "relationship global", "relationshipglobal", "relationship_global"
|
50
|
-
"relationship global"
|
51
|
-
when :relationshippath, "relationship path", "relationshippath", "relationship_path"
|
52
|
-
"relationship path"
|
53
|
-
when :relationshiprecent, "relationship recent", "relationshiprecent", "relationship_recent"
|
54
|
-
"relationship recent"
|
55
|
-
else
|
56
|
-
"none"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_depth(depth)
|
61
|
-
return nil if depth.nil?
|
62
|
-
return 1 if depth.to_i == 0
|
63
|
-
depth.to_i
|
64
|
-
end
|
18
|
+
type = parse_type(return_type)
|
65
19
|
|
66
|
-
|
67
|
-
case type
|
68
|
-
when :relationship, "relationship", :relationships, "relationships"
|
69
|
-
"relationship"
|
70
|
-
when :path, "path", :paths, "paths"
|
71
|
-
"path"
|
72
|
-
when :fullpath, "fullpath", :fullpaths, "fullpaths"
|
73
|
-
"fullpath"
|
74
|
-
else
|
75
|
-
"node"
|
76
|
-
end
|
20
|
+
@connection.post("/node/%{id}/traverse/%{type}" % {:id => get_id(id), :type => type}, options) || []
|
77
21
|
end
|
78
22
|
|
79
23
|
end
|
data/lib/neography/rest/nodes.rb
CHANGED
@@ -1,67 +1,59 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module Nodes
|
5
4
|
include Neography::Rest::Helpers
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(connection)
|
11
|
-
@connection ||= connection
|
12
|
-
end
|
13
|
-
|
14
|
-
def get(id)
|
15
|
-
@connection.get(base_path(:id => get_id(id)))
|
6
|
+
def get_node(id)
|
7
|
+
@connection.get("/node/%{id}" % {:id => get_id(id)})
|
16
8
|
end
|
17
9
|
|
18
|
-
def
|
10
|
+
def get_nodes(*nodes)
|
19
11
|
gotten_nodes = []
|
20
12
|
Array(nodes).flatten.each do |node|
|
21
|
-
gotten_nodes <<
|
13
|
+
gotten_nodes << get_node(node)
|
22
14
|
end
|
23
15
|
gotten_nodes
|
24
16
|
end
|
25
17
|
|
26
|
-
def
|
18
|
+
def get_root
|
27
19
|
root_node = @connection.get('/')["reference_node"]
|
28
|
-
@connection.get(
|
20
|
+
@connection.get("/node/%{id}" % {:id => get_id(root_node)})
|
29
21
|
end
|
30
22
|
|
31
|
-
def
|
23
|
+
def create_node(*args)
|
32
24
|
if args[0].respond_to?(:each_pair) && args[0]
|
33
|
-
|
25
|
+
create_node_with_attributes(args[0])
|
34
26
|
else
|
35
|
-
|
27
|
+
create_empty_node
|
36
28
|
end
|
37
29
|
end
|
38
30
|
|
39
|
-
def
|
31
|
+
def create_node_with_attributes(attributes)
|
40
32
|
options = {
|
41
33
|
:body => attributes.delete_if { |k, v| v.nil? }.to_json,
|
42
34
|
:headers => json_content_type
|
43
35
|
}
|
44
|
-
@connection.post(
|
36
|
+
@connection.post("/node", options)
|
45
37
|
end
|
46
38
|
|
47
|
-
def
|
48
|
-
@connection.post(
|
39
|
+
def create_empty_node
|
40
|
+
@connection.post("/node")
|
49
41
|
end
|
50
42
|
|
51
|
-
def
|
52
|
-
@connection.delete(
|
43
|
+
def delete_node(id)
|
44
|
+
@connection.delete("/node/%{id}" % {:id => get_id(id)})
|
53
45
|
end
|
54
46
|
|
55
|
-
def
|
47
|
+
def create_nodes(nodes)
|
56
48
|
nodes = Array.new(nodes) if nodes.kind_of? Fixnum
|
57
49
|
created_nodes = []
|
58
50
|
nodes.each do |node|
|
59
|
-
created_nodes <<
|
51
|
+
created_nodes << create_node(node)
|
60
52
|
end
|
61
53
|
created_nodes
|
62
54
|
end
|
63
55
|
|
64
|
-
def
|
56
|
+
def create_nodes_threaded(nodes)
|
65
57
|
nodes = Array.new(nodes) if nodes.kind_of? Fixnum
|
66
58
|
|
67
59
|
node_queue = Queue.new
|
@@ -77,12 +69,12 @@ module Neography
|
|
77
69
|
until node_queue.empty? do
|
78
70
|
node = node_queue.pop
|
79
71
|
if node.respond_to?(:each_pair)
|
80
|
-
responses.push( @connection.post(
|
72
|
+
responses.push( @connection.post("/node", {
|
81
73
|
:body => node.to_json,
|
82
74
|
:headers => json_content_type
|
83
75
|
} ) )
|
84
76
|
else
|
85
|
-
responses.push( @connection.post(
|
77
|
+
responses.push( @connection.post("/node") )
|
86
78
|
end
|
87
79
|
end
|
88
80
|
self.join
|
@@ -1,16 +1,9 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module OtherNodeRelationships
|
5
4
|
include Neography::Rest::Helpers
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(connection)
|
10
|
-
@connection ||= connection
|
11
|
-
end
|
12
|
-
|
13
|
-
def get(id, other_id, direction = "all", types = [nil])
|
5
|
+
|
6
|
+
def get_node_relationships_to(id, other_id, direction = "all", types = [nil] )
|
14
7
|
|
15
8
|
body = case parse_direction(direction)
|
16
9
|
when "all"
|
@@ -21,9 +14,9 @@ module Neography
|
|
21
14
|
"position.length() > 0 && position.lastRelationship().getEndNode().getId() == " + get_id(other_id)
|
22
15
|
end
|
23
16
|
|
24
|
-
relationships = {:relationships => types.map{|row| Hash[{:type => row}].merge({:direction => parse_direction(direction)})} }
|
17
|
+
relationships = {:relationships => Array(types).map{|row| Hash[{:type => row}].merge({:direction => parse_direction(direction)})} }
|
25
18
|
|
26
|
-
if types.first.nil?
|
19
|
+
if Array(types).first.nil?
|
27
20
|
relationships = {}
|
28
21
|
end
|
29
22
|
|
@@ -37,7 +30,7 @@ module Neography
|
|
37
30
|
:headers => json_content_type
|
38
31
|
}
|
39
32
|
|
40
|
-
@connection.post(
|
33
|
+
@connection.post("/node/%{id}/traverse/relationship" % {:id => get_id(id)}, options) || []
|
41
34
|
end
|
42
35
|
|
43
36
|
end
|
@@ -1,13 +1,59 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module RelationshipAutoIndexes
|
4
|
+
|
5
|
+
def get_relationship_auto_index(key, value)
|
6
|
+
index = @connection.get("/index/auto/relationship/%{key}/%{value}" % {:key => key, :value => encode(value)}) || []
|
7
|
+
return nil if index.empty?
|
8
|
+
index
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_relationship_auto_index(key_or_query, value = nil)
|
12
|
+
if value
|
13
|
+
index = find_relationship_auto_index_by_value(key_or_query, value)
|
14
|
+
else
|
15
|
+
index = query_relationship_auto_index(key_or_query)
|
16
|
+
end
|
17
|
+
return nil if index.empty?
|
18
|
+
index
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_relationship_auto_index_by_value(key, value)
|
22
|
+
@connection.get("/index/auto/relationship/%{key}/%{value}" % {:key => key, :value => encode(value)}) || []
|
23
|
+
end
|
24
|
+
|
25
|
+
def query_relationship_auto_index(query_expression)
|
26
|
+
@connection.get("/index/auto/relationship/?query=%{query}" % {:query => query_expression}) || []
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_relationship_auto_index_status
|
30
|
+
@connection.get("/index/auto/relationship/status")
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_relationship_auto_index_status(value = true)
|
34
|
+
options = {
|
35
|
+
:body => value.to_json,
|
36
|
+
:headers => json_content_type
|
37
|
+
}
|
38
|
+
@connection.put("/index/auto/relationship/status", options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_relationship_auto_index_properties
|
42
|
+
@connection.get("/index/auto/relationship/properties")
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_relationship_auto_index_property(property)
|
46
|
+
options = {
|
47
|
+
:body => property,
|
48
|
+
:headers => json_content_type
|
49
|
+
}
|
50
|
+
@connection.post("/index/auto/relationship/properties", options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_relationship_auto_index_property(property)
|
54
|
+
@connection.delete("/index/auto/relationship/properties/%{property}" % {:property => property})
|
55
|
+
end
|
56
|
+
|
11
57
|
|
12
58
|
end
|
13
59
|
end
|
@@ -1,23 +1,99 @@
|
|
1
1
|
module Neography
|
2
2
|
class Rest
|
3
|
-
|
4
|
-
extend Neography::Rest::Paths
|
3
|
+
module RelationshipIndexes
|
5
4
|
include Neography::Rest::Helpers
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
def list_relationship_indexes
|
7
|
+
@connection.get("/index/relationship")
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_relationship_index(name, type = "exact", provider = "lucene", extra_config = nil)
|
11
|
+
config = {
|
12
|
+
:type => type,
|
13
|
+
:provider => provider
|
14
|
+
}
|
15
|
+
config.merge!(extra_config) unless extra_config.nil?
|
16
|
+
options = {
|
17
|
+
:body => (
|
18
|
+
{ :name => name,
|
19
|
+
:config => config
|
20
|
+
}
|
21
|
+
).to_json,
|
22
|
+
:headers => json_content_type
|
23
|
+
}
|
24
|
+
@connection.post("/index/relationship", options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_relationship_auto_index(type = "exact", provider = "lucene")
|
28
|
+
create_relationship_index("relationship_auto_index", type, provider)
|
29
|
+
end
|
15
30
|
|
16
|
-
def
|
17
|
-
|
31
|
+
def add_relationship_to_index(index, key, value, id, unique = false)
|
32
|
+
options = {
|
33
|
+
:body => (
|
34
|
+
{ :uri => @connection.configuration + "/relationship/#{get_id(id)}",
|
35
|
+
:key => key,
|
36
|
+
:value => value
|
37
|
+
}
|
38
|
+
).to_json,
|
39
|
+
:headers => json_content_type
|
40
|
+
}
|
41
|
+
path = unique ? "/index/relationship/%{index}?unique" % {:index => index} : "/index/relationship/%{index}" % {:index => index}
|
42
|
+
@connection.post(path, options)
|
18
43
|
end
|
19
44
|
|
20
|
-
def
|
45
|
+
def get_relationship_index(index, key, value)
|
46
|
+
index = @connection.get("/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
|
47
|
+
return nil if index.empty?
|
48
|
+
index
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_relationship_index(index, key_or_query, value = nil)
|
52
|
+
if value
|
53
|
+
index = find_relationship_index_by_key_value(index, key_or_query, value)
|
54
|
+
else
|
55
|
+
index = find_relationship_index_by_query(index, key_or_query)
|
56
|
+
end
|
57
|
+
return nil if index.empty?
|
58
|
+
index
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_relationship_index_by_key_value(index, key, value)
|
62
|
+
@connection.get("/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
|
63
|
+
end
|
64
|
+
|
65
|
+
def find_relationship_index_by_query(index, query)
|
66
|
+
@connection.get("/index/relationship/%{index}?query=%{query}" % {:index => index, :query => encode(query)}) || []
|
67
|
+
end
|
68
|
+
|
69
|
+
# Mimick original neography API in Rest class.
|
70
|
+
def remove_relationship_from_index(index, id_or_key, id_or_value = nil, id = nil)
|
71
|
+
if id
|
72
|
+
remove_relationship_index_by_value(index, id, id_or_key, id_or_value)
|
73
|
+
elsif id_or_value
|
74
|
+
remove_relationship_index_by_key(index, id_or_value, id_or_key)
|
75
|
+
else
|
76
|
+
remove_relationship_index_by_id(index, id_or_key)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_relationship_index_by_id(index, id)
|
81
|
+
@connection.delete("/index/relationship/%{index}/%{id}" % {:index => index, :id => get_id(id)})
|
82
|
+
end
|
83
|
+
|
84
|
+
def remove_relationship_index_by_key(index, id, key)
|
85
|
+
@connection.delete("/index/relationship/%{index}/%{key}/%{id}" % {:index => index, :id => get_id(id), :key => key})
|
86
|
+
end
|
87
|
+
|
88
|
+
def remove_relationship_index_by_value(index, id, key, value)
|
89
|
+
@connection.delete("/index/relationship/%{index}/%{key}/%{value}/%{id}" % {:index => index, :id => get_id(id), :key => key, :value => encode(value)})
|
90
|
+
end
|
91
|
+
|
92
|
+
def drop_relationship_index(index)
|
93
|
+
@connection.delete("/index/relationship/%{index}" % {:index => index})
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_unique_relationship(index, key, value, type, from, to, props = nil)
|
21
97
|
body = {
|
22
98
|
:key => key,
|
23
99
|
:value => value,
|
@@ -28,7 +104,21 @@ module Neography
|
|
28
104
|
}
|
29
105
|
options = { :body => body.to_json, :headers => json_content_type }
|
30
106
|
|
31
|
-
@connection.post(
|
107
|
+
@connection.post("/index/relationship/%{index}?unique" % {:index => index}, options)
|
108
|
+
end
|
109
|
+
|
110
|
+
def get_or_create_unique_relationship(index, key, value, properties = {})
|
111
|
+
options = {
|
112
|
+
:body => (
|
113
|
+
{ :properties => properties,
|
114
|
+
:key => key,
|
115
|
+
:value => value
|
116
|
+
}
|
117
|
+
).to_json,
|
118
|
+
:headers => json_content_type
|
119
|
+
}
|
120
|
+
@connection.post("/index/relationship/%{index}?uniqueness=%{function}" % {:index => index, :function => 'get_or_create'}, options)
|
121
|
+
|
32
122
|
end
|
33
123
|
|
34
124
|
end
|