philippkueng / node-neo4j

Neo4j REST API wrapper for Node.js
MIT License
211 stars 44 forks source link

Cypher query response rows flattened. #30

Closed adambaker closed 10 years ago

adambaker commented 10 years ago

When I execute a cypher query with Neo4j.prototype.cypherQuery, the data results come back with the rows all flattened into one array, when I would have expected an array of rows, each of which should be an array of column values.

Here's a minimal example from my http://localhost:7474/webadmin/#/console/http session:

http> POST /db/data/cypher {"query":"create (:ex {p1: 1, p2: 2}), (:ex {p1: 3, p2: 4})", "params":{}}
==> 200 OK
==> {
==>   "columns" : [ ],
==>   "data" : [ ]
==> }
http> POST /db/data/cypher {"query":"match (n:ex) return n.p1, n.p2", "params":{}}
==> 200 OK
==> {
==>   "columns" : [ "n.p1", "n.p2" ],
==>   "data" : [ [ 1, 2 ], [ 3, 4 ] ]
==> }

With node-neo4j@2.0.0-RC1

neoConnection.cypherQuery("match (n:ex) return n.p1, n.p2", {}, function(err, results){
  console.log(results);
});
//=> { columns: [ 'n.p1', 'n.p2' ], data: [ 1, 2, 3, 4 ] } 
philippkueng commented 10 years ago

Thanks @adambaker for reporting it. That's indeed something that shouldn't be. Will look into it this afternoon.

philippkueng commented 10 years ago

Hi @adambaker,

The issue is now fixed and a new version (node-neo4j@2.0.0-RC3) is deployed to npmjs.org.

As stated in the commit note, in order to make it a little more convenient when only dealing with one RETURN variable and to ensure backwards compatibility as much as possible, you're getting back a flat array when having only 1 RETURN variable, and a nested one when multiple RETURN values are given. Does that work for you?

Thanks for reporting the bug.

Cheers Phil

adambaker commented 10 years ago

Great, thanks.

Flattening at all seems like a mis-feature to me. I don't think the added complexity of both interface and implementation would be justified. I'm also not likely to stumble across it enough for it to matter to me.