Skip to content

Commit

Permalink
adding create unique relationship to batch
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 6, 2012
1 parent 5e4be72 commit 208b317
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,16 @@ To Use:
[: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 [:create_unique_node, index_name, key, value,
{"age" => 33, "name" => "Max"}] # Creates a unique node
@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
@neo.batch [:create_unique_relationship, index_name,
key, value, "friends", node1, node2] # Creates a unique relationship
@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}"],
Expand Down
2 changes: 2 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ def get_batch(args)
{:method => "GET", :to => "/relationship/#{get_id(args[1])}"}
when :create_relationship
{: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 :create_unique_relationship
{:method => "POST", :to => "/index/relationship/#{args[1]}?unique", :body => {:key => args[2], :value => args[3], :type => args[4], :start => (args[5].is_a?(String) && args[5].start_with?("{") ? "" : "/node/") + "#{get_id(args[5])}", :end=> (args[6].is_a?(String) && args[6].start_with?("{") ? "" : "/node/") + "#{get_id(args[6])}"} }
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
Expand Down
13 changes: 13 additions & 0 deletions spec/integration/rest_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@
batch_result.first["body"]["end"].split('/').last.should == node2["self"].split('/').last
end

it "can create a unique relationship" do
index_name = generate_text(6)
key = generate_text(6)
value = generate_text
@neo.create_relationship_index(index_name)
node1 = @neo.create_node
node2 = @neo.create_node
batch_result = @neo.batch [:create_unique_relationship, index_name, key, value, "friends", node1, node2]
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
end

it "can update a single relationship" do
node1 = @neo.create_node
node2 = @neo.create_node
Expand Down

0 comments on commit 208b317

Please sign in to comment.