Skip to content

Commit

Permalink
adding cypher profile and stats options
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jun 17, 2013
1 parent da3081a commit 679591e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ def get_shortest_weighted_path(from, to, relationships, weight_attr = "weight",

# cypher query

def execute_query(query, params = {})
@cypher.query(query, params)
def execute_query(query, params = {}, cypher_options = nil)
@cypher.query(query, params, cypher_options)
end

# gremlin script
Expand Down
15 changes: 12 additions & 3 deletions lib/neography/rest/cypher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ def initialize(connection)
@connection = connection
end

def query(query, parameters = {})
def query(query, parameters = {}, cypher_options = nil)
options = {
:body => {
:query => query,
:params => parameters
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;stream=true'})
}

@connection.post(@connection.cypher_path, options)

@connection.post(optioned_path(cypher_options), options)
end

private
def optioned_path(cypher_options = nil)
return @connection.cypher_path unless cypher_options
options = []
options << "includeStats=true" if cypher_options[:stats]
options << "profile=true" if cypher_options[:profile]
@connection.cypher_path + "?" + options.join("&")
end

end
Expand Down
29 changes: 29 additions & 0 deletions spec/integration/rest_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@
existing_node["data"][0][0]["self"].split('/').last.should == id
end

it "can get the stats of a cypher query" do
root_node = @neo.execute_query("start n=node(0) return n", nil, {:stats => true})
root_node.should have_key("data")
root_node.should have_key("columns")
root_node.should have_key("stats")
root_node["data"][0][0].should have_key("self")
root_node["data"][0][0]["self"].split('/').last.should == "0"
end

it "can get the profile of a cypher query" do
root_node = @neo.execute_query("start n=node(0) return n", nil, {:profile => true})
root_node.should have_key("data")
root_node.should have_key("columns")
root_node.should have_key("plan")
root_node["data"][0][0].should have_key("self")
root_node["data"][0][0]["self"].split('/').last.should == "0"
end

it "can get the stats and profile of a cypher query" do
root_node = @neo.execute_query("start n=node(0) return n", nil, {:stats => true, :profile => true})
root_node.should have_key("data")
root_node.should have_key("columns")
root_node.should have_key("stats")
root_node.should have_key("plan")
root_node["data"][0][0].should have_key("self")
root_node["data"][0][0]["self"].split('/').last.should == "0"
end


it "can delete everything but start node" do
@neo.execute_query("START n=node(*) MATCH n-[r?]-() WHERE ID(n) <> 0 DELETE n,r")
expect {
Expand Down

0 comments on commit 679591e

Please sign in to comment.