Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/neo4j/core/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@ def to_cypher(options = {})
cypher_parts.join(join_string).tap(&:strip!)
end.join(join_string)

cypher_string = "CYPHER #{@options[:parser]} #{cypher_string}" if @options[:parser]
cypher_query_options = []
cypher_query_options << @options[:parser] if @options[:parser]
cypher_query_options << "planner=#{@options[:planner]}" if @options[:planner]
cypher_query_options << "runtime=#{@options[:runtime]}" if @options[:runtime]
cypher_string = "CYPHER #{cypher_query_options.join(' ')} #{cypher_string}" unless cypher_query_options.empty?

cypher_string.tap(&:strip!)
end
alias cypher to_cypher
Expand Down
33 changes: 29 additions & 4 deletions spec/neo4j/core/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,42 @@ def add_query_doc_line(context_class, query_code, cypher, params = {})
end

describe 'options' do
let(:query) { Neo4j::Core::Query.new(parser: 2.0) }
let(:query_options) { { parser: 2.0, planner: 'cost', runtime: 'compiled' } }
let(:query) { Neo4j::Core::Query.new(query_options) }

it 'should generate a per-query cypher parser version' do
expect(query.to_cypher).to eq('CYPHER 2.0')
it 'should generate a per-query cypher parser version, planner and runtime' do
expect(query.to_cypher).to eq('CYPHER 2.0 planner=cost runtime=compiled')
end

describe 'parser only' do
let(:query_options) { { parser: 2.0 } }

it 'should generate a per-query cypher parser version' do
expect(query.to_cypher).to eq('CYPHER 2.0')
end
end

describe 'planner only' do
let(:query_options) { { planner: 'cost' } }

it 'should generate a per-query cypher planner' do
expect(query.to_cypher).to eq('CYPHER planner=cost')
end
end

describe 'runtime only' do
let(:query_options) { { runtime: 'compiled' } }

it 'should generate a per-query cypher runtime' do
expect(query.to_cypher).to eq('CYPHER runtime=compiled')
end
end

describe 'subsequent call' do
let(:query) { super().match('q:Person') }

it 'should combine the parser version with the rest of the query' do
expect(query.to_cypher).to eq('CYPHER 2.0 MATCH q:Person')
expect(query.to_cypher).to eq('CYPHER 2.0 planner=cost runtime=compiled MATCH q:Person')
end
end
end
Expand Down