From b211af06d098e0141eb1da77666a913c57bc390a Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Wed, 4 Jan 2012 05:22:08 +0000 Subject: [PATCH 1/9] starting naive batch implementation --- lib/neography/rest.rb | 22 +++++++ spec/integration/rest_batch_spec.rb | 90 +++++++++++++++++++++++++---- 2 files changed, 100 insertions(+), 12 deletions(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index df9a2b6..9d100e2 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -352,9 +352,31 @@ def execute_script(script) result = post("/ext/GremlinPlugin/graphdb/execute_script", options) result == "null" ? nil : result end + + def batch(*args) + batch = [] + Array(args).each_with_index do |c,i| + batch << {:id => i}.merge(get_batch(c)) + end + options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} } + post("/batch", options) + end private + def get_batch(args) + case args[0] + when :get_node + {:method => "GET", :to => "/node/#{get_id(args[1])}", :body => args[2]} + when :create_node + {:method => "POST", :to => "/node/", :body => args[1]} + when :set_node_property + {:method => "PUT", :to => "/node/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first} + when :reset_node_properties + {:method => "PUT", :to => "/node/#{get_id(args[1])}/properties", :body => args[2]} + end + end + def evaluate_response(response) code = response.code body = response.body diff --git a/spec/integration/rest_batch_spec.rb b/spec/integration/rest_batch_spec.rb index a7cd72e..158b072 100644 --- a/spec/integration/rest_batch_spec.rb +++ b/spec/integration/rest_batch_spec.rb @@ -7,27 +7,93 @@ describe "simple batch" do it "can get a single node" do - pending + new_node = @neo.create_node + new_node[:id] = new_node["self"].split('/').last + batch_result = @neo.batch [:get_node, new_node] + batch_result.first.should_not be_nil + batch_result.first.should have_key("id") + batch_result.first.should have_key("body") + batch_result.first.should have_key("from") + batch_result.first["body"]["self"].split('/').last.should == new_node[:id] end it "can get multiple nodes" do - pending - end + node1 = @neo.create_node + node1[:id] = node1["self"].split('/').last + node2 = @neo.create_node + node2[:id] = node2["self"].split('/').last - it "can create a single node" do - pending - end + batch_result = @neo.batch [:get_node, node1], [:get_node, node2] + batch_result.first.should_not be_nil + batch_result.first.should have_key("id") + batch_result.first.should have_key("body") + batch_result.first.should have_key("from") + batch_result.first["body"]["self"].split('/').last.should == node1[:id] + batch_result.last.should have_key("id") + batch_result.last.should have_key("body") + batch_result.last.should have_key("from") + batch_result.last["body"]["self"].split('/').last.should == node2[:id] - it "can create multiple nodes" do - pending end - it "can update a single node" do - pending + it "can create a single node" do + batch_result = @neo.batch [:create_node, {"name" => "Max"}] + batch_result.first["body"]["data"]["name"].should == "Max" end - it "can update multiple nodes" do - pending + it "can create multiple nodes" do + batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}] + batch_result.first["body"]["data"]["name"].should == "Max" + batch_result.last["body"]["data"]["name"].should == "Marc" + end + + it "can update a property of a node" do + new_node = @neo.create_node("name" => "Max") + batch_result = @neo.batch [:set_node_property, new_node, {"name" => "Marc"}] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + existing_node = @neo.get_node(new_node) + existing_node["data"]["name"].should == "Marc" + end + + it "can update a property of multiple nodes" do + node1 = @neo.create_node("name" => "Max") + node2 = @neo.create_node("name" => "Marc") + batch_result = @neo.batch [:set_node_property, node1, {"name" => "Tom"}], [:set_node_property, node2, {"name" => "Jerry"}] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + batch_result.last.should have_key("id") + batch_result.last.should have_key("from") + existing_node = @neo.get_node(node1) + existing_node["data"]["name"].should == "Tom" + existing_node = @neo.get_node(node2) + existing_node["data"]["name"].should == "Jerry" + end + + it "can reset the properties of a node" do + new_node = @neo.create_node("name" => "Max", "weight" => 200) + batch_result = @neo.batch [:reset_node_properties, new_node, {"name" => "Marc"}] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + existing_node = @neo.get_node(new_node) + existing_node["data"]["name"].should == "Marc" + existing_node["data"]["weight"].should be_nil + end + + it "can reset the properties of multiple nodes" do + node1 = @neo.create_node("name" => "Max", "weight" => 200) + node2 = @neo.create_node("name" => "Marc", "weight" => 180) + batch_result = @neo.batch [:reset_node_properties, node1, {"name" => "Tom"}], [:reset_node_properties, node2, {"name" => "Jerry"}] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + batch_result.last.should have_key("id") + batch_result.last.should have_key("from") + existing_node = @neo.get_node(node1) + existing_node["data"]["name"].should == "Tom" + existing_node["data"]["weight"].should be_nil + existing_node = @neo.get_node(node2) + existing_node["data"]["name"].should == "Jerry" + existing_node["data"]["weight"].should be_nil end it "can get a single relationship" do From 92ce780168b701d8be1829a85d5b30ddddd87352 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Wed, 4 Jan 2012 06:29:31 +0000 Subject: [PATCH 2/9] more batching functions --- README.rdoc | 14 ++++++++ lib/neography/rest.rb | 13 +++++-- spec/integration/rest_batch_spec.rb | 54 ++++++++++++++++++++--------- 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/README.rdoc b/README.rdoc index 3f87997..45b8fdb 100644 --- a/README.rdoc +++ b/README.rdoc @@ -158,6 +158,20 @@ To Use: Please see the specs for more examples. +Batch (in progress): + + @neo.batch [:get_node, node1], [:get_node, node2] # Gets two nodes in a batch + @neo.batch [:create_node, {"name" => "Max"}], + [:create_node, {"name" => "Marc"}] # Creates two nodes in a batch + @neo.batch [:set_node_property, node1, {"name" => "Tom"}], + [:set_node_property, node2, {"name" => "Jerry"}] # Sets the property of two nodes + @neo.batch [:get_relationship, rel1], + [:get_relationship, rel2] # Gets two relationships in a batch + @neo.batch [:create_relationship, "friends", + node1, node2, {:since => "high school"}] + [:create_relationship, "friends", + node1, node3, {:since => "college"}] # Creates two relationships in a batch + Experimental: nodes = @neo.create_nodes(5) # Create 5 empty nodes diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 9d100e2..c8ca341 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -253,7 +253,6 @@ def create_node_index(name, type = "exact", provider = "lucene") def add_node_to_index(index, key, value, id) options = { :body => ({:uri => self.configuration + "/node/#{get_id(id)}", :key => key, :value => value }).to_json, :headers => {'Content-Type' => 'application/json'} } - #post("/index/node/#{index}/#{key}/#{value}", options) post("/index/node/#{index}", options) end @@ -367,13 +366,23 @@ def batch(*args) def get_batch(args) case args[0] when :get_node - {:method => "GET", :to => "/node/#{get_id(args[1])}", :body => args[2]} + {:method => "GET", :to => "/node/#{get_id(args[1])}"} when :create_node {:method => "POST", :to => "/node/", :body => args[1]} when :set_node_property {:method => "PUT", :to => "/node/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first} when :reset_node_properties {:method => "PUT", :to => "/node/#{get_id(args[1])}/properties", :body => args[2]} + when :get_relationship + {:method => "GET", :to => "/relationship/#{get_id(args[1])}"} + when :create_relationship + {:method => "POST", :to => "/node/#{get_id(args[2])}/relationships", :body => {:to => "/node/#{get_id(args[3])}", :type => args[1], :data => args[4] } } + when :set_relationship_property + {:method => "PUT", :to => "/relationship/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first} + when :reset_relationship_properties + {:method => "PUT", :to => "/relationship/#{get_id(args[1])}/properties", :body => args[2]} + when :add_node_to_index + {:method => "POST", :to => "/index/node/#{args[1]}", :body => {:uri => "/node/#{get_id(args[4])}", :key => args[2], :value => args[3] } } end end diff --git a/spec/integration/rest_batch_spec.rb b/spec/integration/rest_batch_spec.rb index 158b072..639bfbd 100644 --- a/spec/integration/rest_batch_spec.rb +++ b/spec/integration/rest_batch_spec.rb @@ -97,31 +97,53 @@ end it "can get a single relationship" do - pending + node1 = @neo.create_node + node2 = @neo.create_node + new_relationship = @neo.create_relationship("friends", node1, node2) + batch_result = @neo.batch [:get_relationship, new_relationship] + batch_result.first["body"]["type"].should == "friends" + batch_result.first["body"]["start"].split('/').last.should == node1["self"].split('/').last + batch_result.first["body"]["end"].split('/').last.should == node2["self"].split('/').last + batch_result.first["body"]["self"].should == new_relationship["self"] end - it "can get multiple relationships" do - pending - end - it "can create a single relationship" do - pending - end - - it "can create multiple relationships" do - pending + node1 = @neo.create_node + node2 = @neo.create_node + batch_result = @neo.batch [:create_relationship, "friends", node1, node2, {:since => "high school"}] + batch_result.first["body"]["type"].should == "friends" + batch_result.first["body"]["data"]["since"].should == "high school" + batch_result.first["body"]["start"].split('/').last.should == node1["self"].split('/').last + batch_result.first["body"]["end"].split('/').last.should == node2["self"].split('/').last end it "can update a single relationship" do - pending - end - - it "can update multiple relationships" do - pending + node1 = @neo.create_node + node2 = @neo.create_node + new_relationship = @neo.create_relationship("friends", node1, node2, {:since => "high school"}) + batch_result = @neo.batch [:set_relationship_property, new_relationship, {:since => "college"}] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + existing_relationship = @neo.get_relationship(new_relationship) + existing_relationship["type"].should == "friends" + existing_relationship["data"]["since"].should == "college" + existing_relationship["start"].split('/').last.should == node1["self"].split('/').last + existing_relationship["end"].split('/').last.should == node2["self"].split('/').last + existing_relationship["self"].should == new_relationship["self"] end it "can add a node to an index" do - pending + new_node = @neo.create_node + key = generate_text(6) + value = generate_text + new_index = @neo.get_node_index("test_node_index", key, value) + batch_result = @neo.batch [:add_node_to_index, "test_node_index", key, value, new_node] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + existing_index = @neo.find_node_index("test_node_index", key, value) + existing_index.should_not be_nil + existing_index.first["self"].should == new_node["self"] + @neo.remove_node_from_index("test_node_index", key, value, new_node) end end From 8f15c033d4ae104043a8f26229722566b9810599 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Thu, 5 Jan 2012 03:19:12 +0000 Subject: [PATCH 3/9] adding more batching functions, now with referencing --- README.rdoc | 10 ++++++ lib/neography/rest.rb | 6 ++-- spec/integration/rest_batch_spec.rb | 54 ++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/README.rdoc b/README.rdoc index 45b8fdb..f2cfcbd 100644 --- a/README.rdoc +++ b/README.rdoc @@ -171,6 +171,16 @@ Batch (in progress): node1, node2, {:since => "high school"}] [:create_relationship, "friends", node1, node3, {:since => "college"}] # Creates two relationships in a batch + @neo.batch [:create_node, {"name" => "Max"}], + [:create_node, {"name" => "Marc"}], # Creates two nodes and index them + [:add_node_to_index, "test_node_index", key, value, "{0}"] + [:add_node_to_index, "test_node_index", key, value, "{1}"] + [:create_relationship, "friends", # and create a relationship for those + "{0}", "{1}", {:since => "college"}] # newly created nodes + [:add_relationship_to_index, + "test_relationship_index", key, value, "{4}"] # and index the new relationship + +See http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html for Neo4j Batch operations documentation. Experimental: diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index c8ca341..fc660d5 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -376,13 +376,15 @@ def get_batch(args) when :get_relationship {:method => "GET", :to => "/relationship/#{get_id(args[1])}"} when :create_relationship - {:method => "POST", :to => "/node/#{get_id(args[2])}/relationships", :body => {:to => "/node/#{get_id(args[3])}", :type => args[1], :data => args[4] } } + {:method => "POST", :to => (args[2].is_a?(String) && args[2].start_with?("{") ? "" : "/node/") + "#{get_id(args[2])}/relationships", :body => {:to => (args[3].is_a?(String) && args[3].start_with?("{") ? "" : "/node/") + "#{get_id(args[3])}", :type => args[1], :data => args[4] } } when :set_relationship_property {:method => "PUT", :to => "/relationship/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first} when :reset_relationship_properties {:method => "PUT", :to => "/relationship/#{get_id(args[1])}/properties", :body => args[2]} when :add_node_to_index - {:method => "POST", :to => "/index/node/#{args[1]}", :body => {:uri => "/node/#{get_id(args[4])}", :key => args[2], :value => args[3] } } + {:method => "POST", :to => "/index/node/#{args[1]}", :body => {:uri => (args[4].is_a?(String) && args[4].start_with?("{") ? "" : "/node/") + "#{get_id(args[4])}", :key => args[2], :value => args[3] } } + when :add_relationship_to_index + {:method => "POST", :to => "/index/relationship/#{args[1]}", :body => {:uri => (args[4].is_a?(String) && args[4].start_with?("{") ? "" : "/relationship/") + "#{get_id(args[4])}", :key => args[2], :value => args[3] } } end end diff --git a/spec/integration/rest_batch_spec.rb b/spec/integration/rest_batch_spec.rb index 639bfbd..e3fb013 100644 --- a/spec/integration/rest_batch_spec.rb +++ b/spec/integration/rest_batch_spec.rb @@ -149,19 +149,65 @@ describe "referenced batch" do it "can create a relationship from two newly created nodes" do - pending + batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}], [:create_relationship, "friends", "{0}", "{1}", {:since => "high school"}] + batch_result.first["body"]["data"]["name"].should == "Max" + batch_result[1]["body"]["data"]["name"].should == "Marc" + batch_result.last["body"]["type"].should == "friends" + batch_result.last["body"]["data"]["since"].should == "high school" + batch_result.last["body"]["start"].split('/').last.should == batch_result.first["body"]["self"].split('/').last + batch_result.last["body"]["end"].split('/').last.should == batch_result[1]["body"]["self"].split('/').last end it "can create a relationship from an existing node and a newly created node" do - pending + node1 = @neo.create_node("name" => "Max", "weight" => 200) + batch_result = @neo.batch [:create_node, {"name" => "Marc"}], [:create_relationship, "friends", "{0}", node1, {:since => "high school"}] + batch_result.first["body"]["data"]["name"].should == "Marc" + batch_result.last["body"]["type"].should == "friends" + batch_result.last["body"]["data"]["since"].should == "high school" + batch_result.last["body"]["start"].split('/').last.should == batch_result.first["body"]["self"].split('/').last + batch_result.last["body"]["end"].split('/').last.should == node1["self"].split('/').last end it "can add a newly created node to an index" do - pending + key = generate_text(6) + value = generate_text + new_index = @neo.get_node_index("test_node_index", key, value) + batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:add_node_to_index, "test_node_index", key, value, "{0}"] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + existing_index = @neo.find_node_index("test_node_index", key, value) + existing_index.should_not be_nil + existing_index.first["self"].should == batch_result.first["body"]["self"] + @neo.remove_node_from_index("test_node_index", key, value, batch_result.first["body"]["self"].split('/').last) end it "can add a newly created relationship to an index" do - pending + key = generate_text(6) + value = generate_text + node1 = @neo.create_node + node2 = @neo.create_node + batch_result = @neo.batch [:create_relationship, "friends", node1, node2, {:since => "high school"}], [:add_relationship_to_index, "test_relationship_index", key, value, "{0}"] + batch_result.first["body"]["type"].should == "friends" + batch_result.first["body"]["data"]["since"].should == "high school" + batch_result.first["body"]["start"].split('/').last.should == node1["self"].split('/').last + batch_result.first["body"]["end"].split('/').last.should == node2["self"].split('/').last + existing_index = @neo.find_relationship_index("test_relationship_index", key, value) + existing_index.should_not be_nil + existing_index.first["self"].should == batch_result.first["body"]["self"] + + end + + it "can kitchen sink" do + key = generate_text(6) + value = generate_text + + batch_result = @neo.batch [:create_node, {"name" => "Max"}], + [:create_node, {"name" => "Marc"}], + [:add_node_to_index, "test_node_index", key, value, "{0}"] + [:add_node_to_index, "test_node_index", key, value, "{1}"] + [:create_relationship, "friends", "{0}", "{1}", {:since => "college"}] + [:add_relationship_to_index, "test_relationship_index", key, value, "{4}"] + batch_result.should_not be_nil end end From ee2335e618d64eb61beb33296b4bea5f5a8cf684 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Thu, 5 Jan 2012 03:20:33 +0000 Subject: [PATCH 4/9] Bump to 0.0.19 --- lib/neography/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/neography/version.rb b/lib/neography/version.rb index 56386ad..6000650 100644 --- a/lib/neography/version.rb +++ b/lib/neography/version.rb @@ -1,3 +1,3 @@ module Neography - VERSION = "0.0.18" + VERSION = "0.0.19" end From c1eef084ad995c1a50eb85d99db743047327537b Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Sat, 7 Jan 2012 01:43:33 +0000 Subject: [PATCH 5/9] making gremlin script parameter aware --- lib/neography/rest.rb | 4 ++-- spec/integration/rest_plugin_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index fc660d5..d593366 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -346,8 +346,8 @@ def execute_query(query) result = post("/ext/CypherPlugin/graphdb/execute_query", options) end - def execute_script(script) - options = { :body => "script=" + CGI::escape(script), :headers => {'Content-Type' => 'application/x-www-form-urlencoded'} } + def execute_script(script, params = {}) + options = { :body => {:script => script, :params => params}.to_json , :headers => {'Content-Type' => 'application/json'} } result = post("/ext/GremlinPlugin/graphdb/execute_script", options) result == "null" ? nil : result end diff --git a/spec/integration/rest_plugin_spec.rb b/spec/integration/rest_plugin_spec.rb index 222d962..2254256 100644 --- a/spec/integration/rest_plugin_spec.rb +++ b/spec/integration/rest_plugin_spec.rb @@ -11,6 +11,27 @@ root_node.should have_key("self") root_node["self"].split('/').last.should == "0" end + + it "can get the a node" do + new_node = @neo.create_node + id = new_node["self"].split('/').last + existing_node = @neo.execute_script("g.v(#{id})") + existing_node.should_not be_nil + existing_node.should have_key("self") + existing_node["self"].split('/').last.should == id + end + + it "can get the a node with a variable" do + new_node = @neo.create_node + id = new_node["self"].split('/').last + existing_node = @neo.execute_script("g.v(id)", {:id => id}) + existing_node.should_not be_nil + existing_node.should have_key("self") + existing_node["self"].split('/').last.should == id + end + + + end describe "execute cypher query" do From c88b20abc7ab99812a1296b23855c9b894851280 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Sat, 7 Jan 2012 02:04:35 +0000 Subject: [PATCH 6/9] adding parameters to cypher calls --- Gemfile.lock | 3 +-- README.rdoc | 6 +++++- lib/neography/rest.rb | 7 ++++++- neography.gemspec | 4 ++-- spec/integration/rest_plugin_spec.rb | 28 ++++++++++++++++++++++++---- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8f478aa..e42f8fb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - neography (0.0.17) + neography (0.0.19) httparty (= 0.7.8) json os @@ -15,7 +15,6 @@ GEM httparty (0.7.8) crack (= 0.1.8) json (1.6.4) - json (1.6.4-java) net-http-spy (0.2.1) os (0.9.5) rake (0.8.7) diff --git a/README.rdoc b/README.rdoc index f2cfcbd..0208327 100644 --- a/README.rdoc +++ b/README.rdoc @@ -30,6 +30,8 @@ in order to access the functionality. === Dependencies for use: + os + rake json httparty @@ -133,8 +135,10 @@ To Use: @neo.get_relationship_index(index, key, value) # exact query of the relationship index with the given key/value pair @neo.find_relationship_index(index, key, value) # advanced query of the relationship index with the given key/value pair @neo.find_relationship_index(index, query) # advanced query of the relationship index with the given query - @neo.execute_script("g.v(0)") # sends a Groovy script(through the Gremlin plugin) + @neo.execute_script("g.v(0)") # sends a Groovy script (through the Gremlin plugin) + @neo.execute_script("g.v(id)", {:id => 3}) # sends a parameterized Groovy script (optimized for repeated calls) @neo.execute_query("start n=node(0) return n") # sends a Cypher query (through the Cypher plugin) + @neo.execute_query("start n=node(id) return n", {:id => 3}) # sends a parameterized Cypher query (optimized for repeated calls) @neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes @neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index d593366..b6e8cc5 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -341,10 +341,15 @@ def get_paths(from, to, relationships, depth=1, algorithm="allPaths") paths = post("/node/#{get_id(from)}/paths", options) || Array.new end - def execute_query(query) + def execute_query_old(query) options = { :body => {:query => query}.to_json, :headers => {'Content-Type' => 'application/json'} } result = post("/ext/CypherPlugin/graphdb/execute_query", options) end + + def execute_query(query, params = {}) + options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json'} } + result = post("/ext/CypherPlugin/graphdb/execute_query", options) + end def execute_script(script, params = {}) options = { :body => {:script => script, :params => params}.to_json , :headers => {'Content-Type' => 'application/json'} } diff --git a/neography.gemspec b/neography.gemspec index 6652c13..5891cbc 100644 --- a/neography.gemspec +++ b/neography.gemspec @@ -21,8 +21,8 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec" s.add_development_dependency "net-http-spy", "0.2.1" - s.add_development_dependency "rake", "~> 0.8.7" - s.add_dependency "httparty", "0.7.8" + s.add_development "rake", ">= 0.8.7" + s.add_dependency "httparty", "~> 0.7.8" s.add_dependency "json" s.add_dependency "os" s.add_dependency "rubyzip" diff --git a/spec/integration/rest_plugin_spec.rb b/spec/integration/rest_plugin_spec.rb index 2254256..ec75df7 100644 --- a/spec/integration/rest_plugin_spec.rb +++ b/spec/integration/rest_plugin_spec.rb @@ -24,14 +24,11 @@ it "can get the a node with a variable" do new_node = @neo.create_node id = new_node["self"].split('/').last - existing_node = @neo.execute_script("g.v(id)", {:id => id}) + existing_node = @neo.execute_script("g.v(id)", {:id => id.to_i}) existing_node.should_not be_nil existing_node.should have_key("self") existing_node["self"].split('/').last.should == id end - - - end describe "execute cypher query" do @@ -42,6 +39,29 @@ root_node["data"][0][0].should have_key("self") root_node["data"][0][0]["self"].split('/').last.should == "0" end + + it "can get the a node" do + new_node = @neo.create_node + id = new_node["self"].split('/').last + existing_node = @neo.execute_query("start n=node(#{id}) return n") + existing_node.should_not be_nil + existing_node.should have_key("data") + existing_node.should have_key("columns") + existing_node["data"][0][0].should have_key("self") + existing_node["data"][0][0]["self"].split('/').last.should == id + end + + it "can get the a node with a variable" do + new_node = @neo.create_node + id = new_node["self"].split('/').last + existing_node = @neo.execute_query("start n=node({id}) return n", {:id => id.to_i}) + existing_node.should_not be_nil + existing_node.should have_key("data") + existing_node.should have_key("columns") + existing_node["data"][0][0].should have_key("self") + existing_node["data"][0][0]["self"].split('/').last.should == id + end + end end \ No newline at end of file From ca429b0672ff3a12773d624487f08ded1156a98d Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Sat, 7 Jan 2012 02:06:29 +0000 Subject: [PATCH 7/9] whoops, botched that gemspec change --- neography.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neography.gemspec b/neography.gemspec index 5891cbc..e575243 100644 --- a/neography.gemspec +++ b/neography.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec" s.add_development_dependency "net-http-spy", "0.2.1" - s.add_development "rake", ">= 0.8.7" + s.add_dependency "rake", ">= 0.8.7" s.add_dependency "httparty", "~> 0.7.8" s.add_dependency "json" s.add_dependency "os" From 1e37b32b92bdc453b5c87fa07e30d886a74d9e1d Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Sat, 7 Jan 2012 02:10:55 +0000 Subject: [PATCH 8/9] Bump to 0.0.20 --- lib/neography/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/neography/version.rb b/lib/neography/version.rb index 6000650..6e87c1f 100644 --- a/lib/neography/version.rb +++ b/lib/neography/version.rb @@ -1,3 +1,3 @@ module Neography - VERSION = "0.0.19" + VERSION = "0.0.20" end From eb03523695ff30693faa7a153adf0bba54c91296 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Sat, 7 Jan 2012 19:19:34 +0000 Subject: [PATCH 9/9] batch arrays of arrays --- README.rdoc | 11 +++++++---- spec/integration/rest_batch_spec.rb | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.rdoc b/README.rdoc index 0208327..707c548 100644 --- a/README.rdoc +++ b/README.rdoc @@ -172,18 +172,21 @@ Batch (in progress): @neo.batch [:get_relationship, rel1], [:get_relationship, rel2] # Gets two relationships in a batch @neo.batch [:create_relationship, "friends", - node1, node2, {:since => "high school"}] + node1, node2, {:since => "high school"}], [:create_relationship, "friends", node1, node3, {:since => "college"}] # Creates two relationships in a batch @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}], # Creates two nodes and index them - [:add_node_to_index, "test_node_index", key, value, "{0}"] - [:add_node_to_index, "test_node_index", key, value, "{1}"] + [:add_node_to_index, "test_node_index", key, value, "{0}"], + [:add_node_to_index, "test_node_index", key, value, "{1}"], [:create_relationship, "friends", # and create a relationship for those - "{0}", "{1}", {:since => "college"}] # newly created nodes + "{0}", "{1}", {:since => "college"}], # newly created nodes [:add_relationship_to_index, "test_relationship_index", key, value, "{4}"] # and index the new relationship + @neo.batch *[[:create_node, {"name" => "Max"}], + [:create_node, {"name" => "Marc"}]] # Use the Splat (*) with Arrays of Arrays + See http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html for Neo4j Batch operations documentation. Experimental: diff --git a/spec/integration/rest_batch_spec.rb b/spec/integration/rest_batch_spec.rb index e3fb013..7db6e45 100644 --- a/spec/integration/rest_batch_spec.rb +++ b/spec/integration/rest_batch_spec.rb @@ -47,6 +47,13 @@ batch_result.last["body"]["data"]["name"].should == "Marc" end + it "can create multiple nodes given an *array" do + batch_result = @neo.batch *[[:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}]] + batch_result.first["body"]["data"]["name"].should == "Max" + batch_result.last["body"]["data"]["name"].should == "Marc" + end + + it "can update a property of a node" do new_node = @neo.create_node("name" => "Max") batch_result = @neo.batch [:set_node_property, new_node, {"name" => "Marc"}]