Class: Redgraph::QueryResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/redgraph/query_response.rb

Overview

Wraps the GRAPH.QUERY response, assuming we use the ‘–compact` output.

The response is an array with these objects:

  • header row

  • result rows

  • query stats

Constant Summary collapse

TYPES =
[
  UNKNOWN = 0,
  NULL    = 1,
  STRING  = 2,
  INTEGER = 3,
  BOOLEAN = 4,
  DOUBLE  = 5,
  ARRAY   = 6,
  EDGE    = 7,
  NODE    = 8,
  PATH    = 9,
  MAP     = 10,
  POINT   = 11
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(response, graph) ⇒ QueryResponse

Returns a new instance of QueryResponse.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/redgraph/query_response.rb', line 28

def initialize(response, graph)
  @response = response
  @graph = graph

  case @response.size
  when 3
    @header_row = @response[0]
    @result_rows = @response[1]
    @query_statistics = @response[2]
  when 1 # queries with no RETURN clause
    @header_row = []
    @result_rows = []
    @query_statistics = @response[0]
  end
end

Instance Method Details

#entitiesObject



48
49
50
# File 'lib/redgraph/query_response.rb', line 48

def entities
  @entities ||= parse_header
end

#resultsetObject



52
53
54
# File 'lib/redgraph/query_response.rb', line 52

def resultset
  @resultset ||= parse_resultset
end

#rowsObject

Wraps in custom datatypes if needed



58
59
60
61
62
63
64
65
# File 'lib/redgraph/query_response.rb', line 58

def rows
  @result_rows.map do |column|
    column.map do |data|
      reify_column_item(data)
    end

  end
end

#statsObject



44
45
46
# File 'lib/redgraph/query_response.rb', line 44

def stats
  @stats ||= parse_stats
end