-
Notifications
You must be signed in to change notification settings - Fork 29
Add execute_query #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nsauk
wants to merge
15
commits into
5.0
Choose a base branch
from
execute-query
base: 5.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add execute_query #258
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d5b7beb
Draft execute_query
nsauk 3bb25dc
Fix todo examples
nsauk 751f7c8
Fix parameters in execute_query
nsauk a9437f4
Fix todo examples
nsauk 5233b88
Add spec
nsauk 66958bf
Merge branch '5.0' into execute-query
klobuczek be8ebe7
Add newline on EOF
nsauk 8472b12
Use dynamic dispatch
nsauk 02e7c57
Enable execute_query in testkit for jruby
nsauk d6b0c2a
Disable spec for MRI for now
nsauk 1367a7e
Try ExecuteQuery testkit request
nsauk 31639e3
Fix for review
nsauk ed76a81
Fix testkit request (WIP)
nsauk 60b3ebf
Add execute_query to MRI
nsauk 7afda0e
Enable execute_query spec for MRI
nsauk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,16 @@ module InternalDriver | |
|
||
auto_closable :session | ||
|
||
def execute_query(query, auth_token = nil, config = {}, **parameters) | ||
check do | ||
driver.executable_query(query) | ||
.with_parameters(to_neo(parameters)) | ||
.with_auth_token(auth_token) | ||
.with_config(to_java_config(Neo4j::Driver::QueryConfig, **config)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the order of calls the same as the parameter order. |
||
.execute | ||
end | ||
end | ||
|
||
def session(**session_config) | ||
java_method(:session, [org.neo4j.driver.SessionConfig]) | ||
.call(to_java_config(Neo4j::Driver::SessionConfig, **session_config)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Neo4j::Driver, concurrency: true do | ||
|
||
describe '#execute_query' do | ||
context 'when querying the database' do | ||
it 'accepts query with default auth_token, config hash and parameters' do | ||
expect { | ||
driver.execute_query( | ||
'MATCH (p:Person {age: $age}) RETURN p.name AS name', | ||
nil, | ||
{ database: 'neo4j' }, | ||
age: 42 | ||
) | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context 'when writing to the database' do | ||
it 'accepts query with only keyword parameters' do | ||
expect { | ||
driver.execute_query( | ||
'CREATE (a:Person {name: $name}) CREATE (b:Person {name: $friend}) CREATE (a)-[:KNOWS]->(b)', | ||
name: 'Alice', | ||
friend: 'David' | ||
) | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context 'when reading from the database' do | ||
it 'accepts query with no additional parameters' do | ||
expect { | ||
driver.execute_query('MATCH (p:Person)-[:KNOWS]->(:Person) RETURN p.name AS name') | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context 'when updating the database' do | ||
it 'accepts update query with keyword parameters' do | ||
expect { | ||
driver.execute_query( | ||
'MATCH (p:Person {name: $name}) SET p.age = $age', | ||
name: 'Alice', | ||
age: 42 | ||
) | ||
}.not_to raise_error | ||
end | ||
|
||
it 'accepts relationship creation with keyword parameters' do | ||
expect { | ||
driver.execute_query( | ||
'MATCH (alice:Person {name: $name}) MATCH (bob:Person {name: $friend}) CREATE (alice)-[:KNOWS]->(bob)', | ||
name: 'Alice', | ||
friend: 'Bob' | ||
) | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context 'when deleting from the database' do | ||
it 'accepts delete query with keyword parameters' do | ||
expect { | ||
driver.execute_query( | ||
'MATCH (p:Person {name: $name}) DETACH DELETE p', | ||
name: 'Alice' | ||
) | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context 'when using query configuration' do | ||
it 'accepts nil auth_token with config hash and parameters' do | ||
expect { | ||
driver.execute_query( | ||
'MATCH (p:Person) RETURN p.name', | ||
nil, | ||
{ database: 'neo4j' }, | ||
age: 42 | ||
) | ||
}.not_to raise_error | ||
end | ||
|
||
it 'accepts auth_token with keyword parameters' do | ||
auth_token = Neo4j::Driver::AuthTokens.basic(neo4j_user, neo4j_password) | ||
|
||
expect { | ||
driver.execute_query( | ||
'MATCH (p:Person) RETURN p.name', | ||
auth_token, | ||
age: 42 | ||
) | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context 'when working with query summaries' do | ||
it 'accepts UNWIND query without parameters' do | ||
expect { | ||
driver.execute_query("UNWIND ['Alice', 'Bob'] AS name MERGE (p:Person {name: name})") | ||
}.not_to raise_error | ||
end | ||
|
||
it 'accepts MERGE query with keyword parameters' do | ||
expect { | ||
driver.execute_query( | ||
"MERGE (p:Person {name: $name}) MERGE (p)-[:KNOWS]->(:Person {name: $friend})", | ||
name: 'Mark', | ||
friend: 'Bob' | ||
) | ||
}.not_to raise_error | ||
end | ||
|
||
it 'accepts EXPLAIN query with keyword parameters' do | ||
expect { | ||
driver.execute_query( | ||
'EXPLAIN MATCH (p {name: $name}) RETURN p', | ||
name: 'Alice' | ||
) | ||
}.not_to raise_error | ||
end | ||
|
||
it 'accepts shortestPath query with keyword parameters' do | ||
expect { | ||
driver.execute_query( | ||
"MATCH p=shortestPath((:Person {name: $start})-[*]->(:Person {name: $end})) RETURN p", | ||
start: 'Alice', | ||
end: 'Bob' | ||
) | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context 'parameter handling' do | ||
it 'handles mixed positional and keyword arguments correctly' do | ||
expect { | ||
driver.execute_query( | ||
'MATCH (p:Person {age: $age, name: $name}) RETURN p', | ||
nil, | ||
{ database: 'neo4j' }, | ||
age: 42, | ||
name: 'Alice' | ||
) | ||
}.not_to raise_error | ||
end | ||
|
||
it 'handles only keyword arguments' do | ||
expect { | ||
driver.execute_query( | ||
'MATCH (p:Person {name: $name}) RETURN p', | ||
name: 'Alice' | ||
) | ||
}.not_to raise_error | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was stumbling on the
driver
until I realized that it might refer to partial package name. We don't such references. The methoddriver
in this context is confusing. Just remove it.