Skip to content

Commit

Permalink
batch arrays of arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 7, 2012
1 parent 1e37b32 commit eb03523
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions spec/integration/rest_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]
Expand Down

0 comments on commit eb03523

Please sign in to comment.