From eab5332bbf7e6d3ba79d2f86c21da921943e2a65 Mon Sep 17 00:00:00 2001 From: Erick Calder Date: Wed, 3 Aug 2016 19:41:19 -0700 Subject: [PATCH] Graph format support for results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this patch enhances the library by allowing use of the ’graph’ format the REST API support (passed in via the resultDataContents field). please note I’ve added a test but am not clever enough to make it pass --- lib-new/GraphDatabase.coffee | 7 +++++-- test-new/cypher._coffee | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib-new/GraphDatabase.coffee b/lib-new/GraphDatabase.coffee index 0a9b05b..5f3df4b 100644 --- a/lib-new/GraphDatabase.coffee +++ b/lib-new/GraphDatabase.coffee @@ -235,7 +235,8 @@ module.exports = class GraphDatabase {query, params, lean} = query # NOTE: Lowercase 'rest' matters here for parsing. - formats.push format = if lean then 'row' else 'rest' + format = if lean is true then 'row' else (lean or 'rest') + formats.push format # NOTE: Braces needed by CoffeeLint for now. # https://github.com/clutchski/coffeelint/issues/459 @@ -285,8 +286,10 @@ module.exports = class GraphDatabase # parse nodes & relationships into object instances if this # query didn't request a raw format. Phew! $(data).pluck(format).map (row) -> - result = {} + if format is 'graph' + return row + result = {} for column, j in columns result[column] = row[j] diff --git a/test-new/cypher._coffee b/test-new/cypher._coffee index 45feacc..12f2afa 100644 --- a/test-new/cypher._coffee +++ b/test-new/cypher._coffee @@ -189,6 +189,24 @@ describe 'GraphDatabase::cypher', -> r: TEST_REL.properties ] + it 'should support graph format results', (_) -> + results = DB.cypher + query: ''' + START a = node({idA}) + MATCH (a) -[r]-> (b) + RETURN a, b, r + ''' + params: + idA: TEST_NODE_A._id + lean: 'graph' + , _ + + expect(results).to.eql [ + a: TEST_NODE_A.properties + b: TEST_NODE_B.properties + r: TEST_REL.properties + ] + it 'should support simple batching', (_) -> results = DB.cypher [ query: '''