-
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
base: 5.0
Are you sure you want to change the base?
Add execute_query #258
Conversation
java_method(:executableQuery, [java.lang.String]) | ||
.call(query) | ||
.java_method(:withParameters, [java.util.Map]) | ||
.call(parameters.transform_keys(&:to_s)) | ||
.java_method(:withAuthToken, [org.neo4j.driver.AuthToken]) | ||
.call(auth_token) | ||
.java_method(:withConfig, [org.neo4j.driver.QueryConfig]) | ||
.call(to_java_config(Neo4j::Driver::QueryConfig, **config)) | ||
.java_method(:execute, []) | ||
.call |
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.
you will need to wrap the entire method with
check do
...
end
which converts potential exceptions from java to ruby exceptions.
.java_method(:withParameters, [java.util.Map]) | ||
.call(parameters.transform_keys(&:to_s)) |
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.
you need to get hold of the actual java method object only in relatively seldom cases. Mostly the methods can be determined dynamically.
I'm quite sure this will work:
.java_method(:withParameters, [java.util.Map]) | |
.call(parameters.transform_keys(&:to_s)) | |
.with_parameters(to_neo(parameters)) |
please note the conversion to_neo
. Keys and values have to be converted.
.call(query) | ||
.java_method(:withParameters, [java.util.Map]) | ||
.call(parameters.transform_keys(&:to_s)) | ||
.java_method(:withAuthToken, [org.neo4j.driver.AuthToken]) |
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.
always check if you really need the explicit method lookup. The dynamic dispatch is so much more readable.
@@ -11,6 +11,16 @@ module InternalDriver | |||
|
|||
auto_closable :session | |||
|
|||
def execute_query(query, auth_token = nil, config = {}, **parameters) | |||
check do | |||
driver.executable_query(query) |
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 method driver
in this context is confusing. Just remove it.
.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 comment
The 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.
alias_method :response_to_testkit, :to_testkit | ||
|
||
include Conversion | ||
alias_method :value_to_testkit, :to_testkit | ||
|
||
include SummaryHelper | ||
|
||
def to_testkit(*args) | ||
if args.empty? | ||
response_to_testkit | ||
else | ||
value_to_testkit(*args) | ||
end | ||
end |
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.
At the moment I managed to make it work with this trick only.
No description provided.