Skip to content

Commit

Permalink
adding parameters to cypher calls
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 7, 2012
1 parent c1eef08 commit c88b20a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
neography (0.0.17)
neography (0.0.19)
httparty (= 0.7.8)
json
os
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ in order to access the functionality.
=== Dependencies

for use:
os
rake
json
httparty

Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'} }
Expand Down
4 changes: 2 additions & 2 deletions neography.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 24 additions & 4 deletions spec/integration/rest_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit c88b20a

Please sign in to comment.