neo4j-core
neo4j-core copied to clipboard
Allow for returning results unwrapped
Both server and embedded modes
Call unwrapped
in your query chain? (Edited to make this a question so it didn't seem so... stern. ;-) )
To clarify: What I meant in this issue was for us to expose an unwrapped
option in #query
I'm currently working on the ROM (ruby object mapper) adapter for Neo4J. neo4j-core underlies this adapter. I've encountered confusing behavior:
Neo4j::Session.query("MATCH (n) RETURN n") # query 1
Neo4j::Session.query.match('(n)').return(:n).to_enum # query 2
These two queries return different types of objects. Both give enumerables of Hash
es where the keys are symbol corresponding to returned items from the query. So far so good. But the values in the query 1 Hash
es are Neo4j::Server::CypherNode
objects, whereas those from query 2 are Hash
es holding the REST response from the server. This is really counterintuitive to me-- why should Session#query
give me a different kind of result depending on if I use a plain string or the Cypher DSL? After all, I assume that Query
objects are rendered to Cypher anyway before being submitted to the server.
It would be good to be able to specify exactly how you want your results wrapped.
Interesting, that definitely sounds buggy to me. I don't think I'm seeing quite what you are, though. Here's what I get:
2.2.3 :012 > Neo4j::Session.query("MATCH (n) RETURN n").first
CYPHER 1247ms MATCH (n) RETURN n
=> #<struct n=#<GraphGist uuid: "dbc52679-2bfe-452c-ada8-4aa9b5a737d5", asciidoc: "= A small social networking website +\n\nThis database is a small example of a networking site where u", created_at: Thu, 29 Oct 2015 08:17:12 +0000, featured: nil, html: "<div id=\"preamble\">\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>This database is a small ex", legacy_id: "d0e4b90e9d6854183793e958706d24ed", legacy_neo_id: 415167, legacy_poster_image: nil, legacy_rated: "6.3", private: false, raw_url: "https://gist.githubusercontent.com/RaulEstrada/8389170/raw/3eda0620bbfb5993700bef6c28d61fa0bbce559a/", status: "live", summary: "This database is a small example of a networking site where users can watch movies, subscribe to TV ", title: "A small social networking website<br>", updated_at: Wed, 04 Nov 2015 06:06:17 +0000, url: nil>>
2.2.3 :013 > Neo4j::Session.query.match('(n)').return(:n).to_enum.first
CYPHER 289ms
MATCH (n)
RETURN n
=> #<struct n=#<GraphGist uuid: "dbc52679-2bfe-452c-ada8-4aa9b5a737d5", asciidoc: "= A small social networking website +\n\nThis database is a small example of a networking site where u", created_at: Thu, 29 Oct 2015 08:17:12 +0000, featured: nil, html: "<div id=\"preamble\">\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>This database is a small ex", legacy_id: "d0e4b90e9d6854183793e958706d24ed", legacy_neo_id: 415167, legacy_poster_image: nil, legacy_rated: "6.3", private: false, raw_url: "https://gist.githubusercontent.com/RaulEstrada/8389170/raw/3eda0620bbfb5993700bef6c28d61fa0bbce559a/", status: "live", summary: "This database is a small example of a networking site where users can watch movies, subscribe to TV ", title: "A small social networking website<br>", updated_at: Wed, 04 Nov 2015 06:06:17 +0000, url: nil>>
I notice in the gemspec
for rom-neo4j
that the version is tied specifically to 5.1.3
. Could you try making that ~> 5.1.11
so that it includes the latest fixes and so that people can update easily to the latest in the 5.1 series? We try our best to follow the http://semver.org/ conventions so it should be safe to do so.
Also be aware that we're about to release 6.0.0. You can try that out by specifying ~> 6.0.0.rc
.
Lastly, you should also be aware that we've been working on a new Session
API which will replace the current one. That's available off to the side in 6.0.0 but it's a bit beta right now. Hopefully we'll be able to release it as part of an upcoming major version (with deprecation warnings) and hopefully it will help us fix any inconsistencies like what you're seeing.
Let us know if upgrading your version doesn't help.
Thanks @cheerfulstoic, I thought I was using the latest version but I must not have been. Using 5.1.11, I no longer see the REST hash response. Both queries now give me the same CypherNode
objects. I don't see the struct
s that you show in your response, but I assume those must be part of 6.0.0.
In any case, it would still be good to be able to specify the return format. For rom-neo4j, I am going to need to convert nodes to hash form anyway, so it will just be extra overhead to have them automatically wrapped.
Agreed about controlling the response format!
What are you seeing instead of struct
s?
So as it turns out there was a monkey patch to rom-neo4j that was causing the issue. It was coercing the results of Query#each
to hashes but not those from the Enumerator you get if you call Session::query
with a raw Cypher string.
Oh gosh! ;) Glad that you got that figured out, thanks!