Class: Tina4Ultipa::Result
- Inherits:
-
Object
- Object
- Tina4Ultipa::Result
- 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
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#current_graph ⇒ Object
readonly
Returns the value of attribute current_graph.
-
#dml_stats ⇒ Object
readonly
Returns the value of attribute dml_stats.
-
#row_count ⇒ Object
readonly
Returns the value of attribute row_count.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#rows_affected ⇒ Object
readonly
Returns the value of attribute rows_affected.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(resp) ⇒ Result
constructor
A new instance of Result.
- #length ⇒ Object (also: #size)
-
#scalar ⇒ Object
The first cell of the first row, or nil.
-
#to_h_rows ⇒ Object
(also: #dicts)
Rows as hashes keyed by column name.
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
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
28 29 30 |
# File 'lib/tina4_ultipa/client.rb', line 28 def columns @columns end |
#current_graph ⇒ Object (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_stats ⇒ Object (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_count ⇒ Object (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 |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
28 29 30 |
# File 'lib/tina4_ultipa/client.rb', line 28 def rows @rows end |
#rows_affected ⇒ Object (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 |
#warnings ⇒ Object (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 |
#length ⇒ Object Also known as: size
67 68 69 |
# File 'lib/tina4_ultipa/client.rb', line 67 def length @rows.length end |
#scalar ⇒ Object
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_rows ⇒ Object 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 |