Class: Vertica::Result
- Inherits:
-
Object
- Object
- Vertica::Result
- Includes:
- Enumerable
- Defined in:
- lib/vertica/result.rb
Overview
Class that represents a buffered resultset.
This class implements the Enumerable interface for easy iteration through the rows. You can also address specific values in the result using #fetch. To leanr more about the shape of the result #row_description will give you an ordered list of all the Columns in this result.
Instance Attribute Summary collapse
-
#row_description ⇒ Vertica::RowDescription
(also: #columns)
readonly
The columns in the result.
-
#tag ⇒ String
readonly
The kind of SQL command that produced this reuslt.
Class Method Summary collapse
-
.build(row_description: nil, rows: [], tag: nil) ⇒ Vertica::Result
Builds a Result from a row description and a list of compatible rows.
Instance Method Summary collapse
-
#each {|row| ... }
Iterates through the resultset.
-
#empty? ⇒ Boolean
Returns
true
if the result has no rows. -
#fetch(row, col = nil) ⇒ Vertica::Row, Object
(also: #[])
Retrieves a row or value from the result.
-
#initialize(row_description: nil, rows: nil, tag: nil) ⇒ Result
constructor
Initializes a new Vertica::Result instance.
-
#size ⇒ Integer
(also: #count, #length)
The number of rows in this result.
-
#value ⇒ Object
(also: #the_value)
Shorthand to return the value of a query that only returns a single value.
Constructor Details
#initialize(row_description: nil, rows: nil, tag: nil) ⇒ Result
Initializes a new Vertica::Result instance.
The constructor assumes that the row description, and the list of rows match up. If you're unsure, use build which will assert this is the case.
40 41 42 |
# File 'lib/vertica/result.rb', line 40 def initialize(row_description: nil, rows: nil, tag: nil) @row_description, @rows, @tag = row_description, rows, tag end |
Instance Attribute Details
#row_description ⇒ Vertica::RowDescription (readonly) Also known as: columns
The columns in the result.
26 27 28 |
# File 'lib/vertica/result.rb', line 26 def row_description @row_description end |
#tag ⇒ String (readonly)
The kind of SQL command that produced this reuslt.
26 27 28 |
# File 'lib/vertica/result.rb', line 26 def tag @tag end |
Class Method Details
.build(row_description: nil, rows: [], tag: nil) ⇒ Vertica::Result
Builds a Vertica::Result from a row description and a list of compatible rows.
107 108 109 110 111 |
# File 'lib/vertica/result.rb', line 107 def self.build(row_description: nil, rows: [], tag: nil) row_description = Vertica::RowDescription.build(row_description) rows = rows.map { |values| row_description.build_row(values) } new(row_description: row_description, rows: rows, tag: tag) end |
Instance Method Details
#each {|row| ... }
This method returns an undefined value.
Iterates through the resultset. This class also includes the Enumerable
interface, which means you can use all the Enumerable
methods like map
and inject
as well.
50 51 52 |
# File 'lib/vertica/result.rb', line 50 def each(&block) @rows.each(&block) end |
#empty? ⇒ Boolean
Returns true
if the result has no rows.
55 56 57 |
# File 'lib/vertica/result.rb', line 55 def empty? @rows.empty? end |
#fetch(row) ⇒ Vertica::Row #fetch(row, column) ⇒ Object Also known as: []
Retrieves a row or value from the result.
82 83 84 85 86 |
# File 'lib/vertica/result.rb', line 82 def fetch(row, col = nil) row = @rows.fetch(row) return row if col.nil? row.fetch(col) end |
#size ⇒ Integer Also known as: count, length
Returns The number of rows in this result.
60 61 62 |
# File 'lib/vertica/result.rb', line 60 def size @rows.length end |
#value ⇒ Object Also known as: the_value
Shorthand to return the value of a query that only returns a single value.
92 93 94 |
# File 'lib/vertica/result.rb', line 92 def value fetch(0, 0) end |