Class: Gloo::Objs::QueryResult
- Inherits:
-
Object
- Object
- Gloo::Objs::QueryResult
- Defined in:
- lib/gloo/objs/data/query_result.rb
Constant Summary collapse
- DB =
'database'.freeze
- SQL =
'sql'.freeze
- RESULT =
'result'.freeze
- PARAMS =
'params'.freeze
Instance Method Summary collapse
-
#has_data_to_show? ⇒ Boolean
Does this query result have data to show?.
-
#initialize(heads, data, engine = nil) ⇒ QueryResult
constructor
Create the Result object.
-
#show ⇒ Object
Show the result of the query.
-
#show_rows ⇒ Object
Show multiple rows in a table view.
-
#show_single_row ⇒ Object
Show a single row in a vertical, form style view.
-
#single_row_result? ⇒ Boolean
Does the data contain a single row?.
-
#update_result_container(in_can) ⇒ Object
Update the result container with the data from the query.
-
#update_result_container_simple(in_can) ⇒ Object
Update the result container with the data from the query.
-
#update_rows ⇒ Object
Put all rows in the result object.
-
#update_rows_simple ⇒ Object
Put all rows in the result object.
-
#update_single_row ⇒ Object
The result has a single row.
Constructor Details
#initialize(heads, data, engine = nil) ⇒ QueryResult
Create the Result object
23 24 25 26 27 |
# File 'lib/gloo/objs/data/query_result.rb', line 23 def initialize( heads, data, engine=nil ) @heads = heads @data = data @engine = engine end |
Instance Method Details
#has_data_to_show? ⇒ Boolean
Does this query result have data to show?
44 45 46 47 48 49 50 51 |
# File 'lib/gloo/objs/data/query_result.rb', line 44 def has_data_to_show? return false unless @heads return false unless @data return false if @heads.count == 0 return false if @data.count == 0 return true end |
#show ⇒ Object
Show the result of the query
61 62 63 |
# File 'lib/gloo/objs/data/query_result.rb', line 61 def show single_row_result? ? show_single_row : show_rows end |
#show_rows ⇒ Object
Show multiple rows in a table view.
80 81 82 |
# File 'lib/gloo/objs/data/query_result.rb', line 80 def show_rows @engine.platform.table.show @heads, @data end |
#show_single_row ⇒ Object
Show a single row in a vertical, form style view.
68 69 70 71 72 73 74 75 |
# File 'lib/gloo/objs/data/query_result.rb', line 68 def show_single_row arr = [] row = @data[0] @heads.each_with_index do |h, i| arr << [ h, row[i] ] end @engine.platform.table.show [ 'Field', 'Value' ], arr end |
#single_row_result? ⇒ Boolean
Does the data contain a single row?
37 38 39 |
# File 'lib/gloo/objs/data/query_result.rb', line 37 def single_row_result? return @data.count == 1 end |
#update_result_container(in_can) ⇒ Object
Update the result container with the data from the query.
91 92 93 94 |
# File 'lib/gloo/objs/data/query_result.rb', line 91 def update_result_container( in_can ) @result_can = in_can single_row_result? ? update_single_row : update_rows end |
#update_result_container_simple(in_can) ⇒ Object
Update the result container with the data from the query.
99 100 101 102 |
# File 'lib/gloo/objs/data/query_result.rb', line 99 def update_result_container_simple( in_can ) @result_can = in_can single_row_result? ? update_single_row : update_rows_simple end |
#update_rows ⇒ Object
Put all rows in the result object.
119 120 121 122 123 124 125 126 127 |
# File 'lib/gloo/objs/data/query_result.rb', line 119 def update_rows @data.each_with_index do |row, i| can = @result_can.find_add_child( i.to_s, 'can' ) row.each_with_index do |v, i| o = can.find_add_child( @heads[i], 'untyped' ) o.set_value v end end end |
#update_rows_simple ⇒ Object
Put all rows in the result object.
132 133 134 135 136 137 138 139 |
# File 'lib/gloo/objs/data/query_result.rb', line 132 def update_rows_simple @data.each do |row| row.each do |val| o = @result_can.find_add_child( val, 'untyped' ) o.set_value val end end end |
#update_single_row ⇒ Object
The result has a single row. Map values from the result set to objects that are present.
108 109 110 111 112 113 114 |
# File 'lib/gloo/objs/data/query_result.rb', line 108 def update_single_row row = @data[0] @heads.each_with_index do |h, i| child = @result_can.find_child h child.set_value row[i] if child end end |