From eb03523695ff30693faa7a153adf0bba54c91296 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Sat, 7 Jan 2012 19:19:34 +0000 Subject: [PATCH] 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"}]