Class: Vertica::Row
Overview
Class to represent a row returns by a query.
Row instances can either be yielded to the block passed to Connection#query, or be part of a buffered Result returned by Connection#query.
Instance Attribute Summary collapse
-
#row_description ⇒ Vertica::RowDescription
readonly
The ordered list of columns this row conforms to.
Instance Method Summary collapse
-
#each {|value| ... } ⇒ Object
Iterates over the values in this row.
-
#eql?(other) ⇒ Boolean
(also: #==)
Returns true iff this record is equal to the other provided object.
-
#fetch(name_or_index) ⇒ Object
(also: #[])
Fetches a value from this row.
-
#hash ⇒ Integer
Returns a hash digtest of this object.
-
#initialize(row_description, values) ⇒ Row
constructor
Initializes a new row instance for a given row description and values.
-
#inspect ⇒ String
Returns a user-consumable string representation of this row.
-
#to_a ⇒ Array
Returns an array representation of the row.
-
#to_h(symbolize_keys: false) ⇒ Hash
Returns a hash representation of this rows, using the name of the fields as keys.
Constructor Details
#initialize(row_description, values) ⇒ Row
Initializes a new row instance for a given row description and values. The number of values MUST match the number of columns in the row description.
21 22 23 |
# File 'lib/vertica/row.rb', line 21 def initialize(row_description, values) @row_description, @values = row_description, values end |
Instance Attribute Details
#row_description ⇒ Vertica::RowDescription (readonly)
The ordered list of columns this row conforms to.
10 11 12 |
# File 'lib/vertica/row.rb', line 10 def row_description @row_description end |
Instance Method Details
#each {|value| ... } ⇒ Object
Iterates over the values in this row.
28 29 30 |
# File 'lib/vertica/row.rb', line 28 def each(&block) @values.each(&block) end |
#eql?(other) ⇒ Boolean Also known as: ==
Returns true iff this record is equal to the other provided object
66 67 68 |
# File 'lib/vertica/row.rb', line 66 def eql?(other) other.kind_of?(Vertica::Row) && other.row_description == row_description && other.to_a == to_a end |
#fetch(name_or_index) ⇒ Object Also known as: []
Fetches a value from this row.
36 37 38 |
# File 'lib/vertica/row.rb', line 36 def fetch(name_or_index) @values.fetch(column_index(name_or_index)) end |
#hash ⇒ Integer
Returns a hash digtest of this object.
73 74 75 |
# File 'lib/vertica/row.rb', line 73 def hash [row_description, values].hash end |
#inspect ⇒ String
Returns a user-consumable string representation of this row.
78 79 80 |
# File 'lib/vertica/row.rb', line 78 def inspect "#<#{self.class.name}#{@values.inspect}>" end |
#to_a ⇒ Array
Returns an array representation of the row. The values will be ordered like the order of the fields in the #row_description.
45 46 47 |
# File 'lib/vertica/row.rb', line 45 def to_a @values end |
#to_h(symbolize_keys: false) ⇒ Hash
Returns a hash representation of this rows, using the name of the fields as keys.
56 57 58 59 60 61 62 63 |
# File 'lib/vertica/row.rb', line 56 def to_h(symbolize_keys: false) @row_description.inject({}) do |carry, column| key = symbolize_keys ? column.name.to_sym : column.name raise Vertica::Error::DuplicateColumnName, "Column with name #{key} occurs more than once in this row." if carry.key?(key) carry[key] = fetch(column.name) carry end end |