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.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tina4_ultipa/client.rb', line 32 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 = { 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 } end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
27 28 29 |
# File 'lib/tina4_ultipa/client.rb', line 27 def columns @columns end |
#current_graph ⇒ Object (readonly)
Returns the value of attribute current_graph.
27 28 29 |
# File 'lib/tina4_ultipa/client.rb', line 27 def current_graph @current_graph end |
#dml_stats ⇒ Object (readonly)
Returns the value of attribute dml_stats.
27 28 29 |
# File 'lib/tina4_ultipa/client.rb', line 27 def dml_stats @dml_stats end |
#row_count ⇒ Object (readonly)
Returns the value of attribute row_count.
27 28 29 |
# File 'lib/tina4_ultipa/client.rb', line 27 def row_count @row_count end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
27 28 29 |
# File 'lib/tina4_ultipa/client.rb', line 27 def rows @rows end |
#rows_affected ⇒ Object (readonly)
Returns the value of attribute rows_affected.
27 28 29 |
# File 'lib/tina4_ultipa/client.rb', line 27 def rows_affected @rows_affected end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
27 28 29 |
# File 'lib/tina4_ultipa/client.rb', line 27 def warnings @warnings end |
Instance Method Details
#each(&block) ⇒ Object
57 58 59 |
# File 'lib/tina4_ultipa/client.rb', line 57 def each(&block) to_h_rows.each(&block) end |
#length ⇒ Object Also known as: size
61 62 63 |
# File 'lib/tina4_ultipa/client.rb', line 61 def length @rows.length end |
#scalar ⇒ Object
The first cell of the first row, or nil.
52 53 54 55 |
# File 'lib/tina4_ultipa/client.rb', line 52 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.
46 47 48 |
# File 'lib/tina4_ultipa/client.rb', line 46 def to_h_rows @rows.map { |row| @columns.zip(row).to_h } end |