Skip to content

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
wants to merge 15 commits into
base: 5.0
Choose a base branch
from
Open

Add execute_query #258

wants to merge 15 commits into from

Conversation

nsauk
Copy link
Contributor

@nsauk nsauk commented Jun 2, 2025

No description provided.

Comment on lines 15 to 24
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
Copy link
Member

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.

Comment on lines 17 to 18
.java_method(:withParameters, [java.util.Map])
.call(parameters.transform_keys(&:to_s))
Copy link
Member

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:

Suggested change
.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])
Copy link
Member

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)
Copy link
Member

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.

Comment on lines 17 to 19
.with_parameters(to_neo(parameters))
.with_auth_token(auth_token)
.with_config(to_java_config(Neo4j::Driver::QueryConfig, **config))
Copy link
Member

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.

Comment on lines +6 to +19
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
Copy link
Contributor Author

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.

@nsauk nsauk changed the title Add execute_query to jruby Add execute_query Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants