Class: Tina4Ultipa::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tina4_ultipa/client.rb

Overview

A gqldb result set - columns + rows, shaped like Tina4's DatabaseResult.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resp) ⇒ Result

Returns a new instance of Result.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tina4_ultipa/client.rb', line 33

def initialize(resp)
  @columns = resp.columns.to_a
  @rows = resp.rows.map { |row| row.values.map { |v| Codec.decode(v) } }
  @row_count = resp.row_count
  @rows_affected = resp.rows_affected
  @warnings = resp.warnings.to_a
  @current_graph = resp.current_graph
  d = resp.dml_stats
  @dml_stats = if d
                 { inserted_nodes: d.inserted_nodes, inserted_edges: d.inserted_edges,
                   deleted_nodes: d.deleted_nodes, deleted_edges: d.deleted_edges,
                   set_nodes: d.set_nodes, set_edges: d.set_edges }
               else
                 { inserted_nodes: 0, inserted_edges: 0, deleted_nodes: 0,
                   deleted_edges: 0, set_nodes: 0, set_edges: 0 }
               end
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



28
29
30
# File 'lib/tina4_ultipa/client.rb', line 28

def columns
  @columns
end

#current_graphObject (readonly)

Returns the value of attribute current_graph.



28
29
30
# File 'lib/tina4_ultipa/client.rb', line 28

def current_graph
  @current_graph
end

#dml_statsObject (readonly)

Returns the value of attribute dml_stats.



28
29
30
# File 'lib/tina4_ultipa/client.rb', line 28

def dml_stats
  @dml_stats
end

#row_countObject (readonly)

Returns the value of attribute row_count.



28
29
30
# File 'lib/tina4_ultipa/client.rb', line 28

def row_count
  @row_count
end

#rowsObject (readonly)

Returns the value of attribute rows.



28
29
30
# File 'lib/tina4_ultipa/client.rb', line 28

def rows
  @rows
end

#rows_affectedObject (readonly)

Returns the value of attribute rows_affected.



28
29
30
# File 'lib/tina4_ultipa/client.rb', line 28

def rows_affected
  @rows_affected
end

#warningsObject (readonly)

Returns the value of attribute warnings.



28
29
30
# File 'lib/tina4_ultipa/client.rb', line 28

def warnings
  @warnings
end

Instance Method Details

#each(&block) ⇒ Object



63
64
65
# File 'lib/tina4_ultipa/client.rb', line 63

def each(&block)
  to_h_rows.each(&block)
end

#lengthObject Also known as: size



67
68
69
# File 'lib/tina4_ultipa/client.rb', line 67

def length
  @rows.length
end

#scalarObject

The first cell of the first row, or nil.



58
59
60
61
# File 'lib/tina4_ultipa/client.rb', line 58

def scalar
  first = @rows[0]
  first && !first.empty? ? first[0] : nil
end

#to_h_rowsObject Also known as: dicts

Rows as hashes keyed by column name.



52
53
54
# File 'lib/tina4_ultipa/client.rb', line 52

def to_h_rows
  @rows.map { |row| @columns.zip(row).to_h }
end