class Vertica::Row

Class to represent a row returns by a query.

Row instances can either be yielded to the block passed to {Vertica::Connection#query}, or be part of a buffered {Vertica::Result} returned by {Vertica::Connection#query}.

@attr_reader row_description [Vertica::RowDescription] The ordered list of columns this

row conforms to.

@see Vertica::RowDescription#build_row

Attributes

row_description[R]

Public Class Methods

new(row_description, values) click to toggle source

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. @param row_description [Vertica::RowDescription] The row description the

values will conform to.

@param values [Array] The values for the columns in the row description @see Vertica::RowDescription#build_row

# File lib/vertica/row.rb, line 21
def initialize(row_description, values)
  @row_description, @values = row_description, values
end

Public Instance Methods

==(other)
Alias for: eql?
[](name_or_index)
Alias for: fetch
each(&block) click to toggle source

Iterates over the values in this row. @yield [value] The provided block will get called with the values in the order of

the columns in the row_description.
# File lib/vertica/row.rb, line 28
def each(&block)
  @values.each(&block)
end
eql?(other) click to toggle source

@return [Boolean] Returns true iff this record is equal to the other provided object

# 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
Also aliased as: ==
fetch(name_or_index) click to toggle source

Fetches a value from this row. @param name_or_index [Symbol, String, Integer] The name of the column as string or symbol,

or the index of the column in the row description.

@raise KeyError A KeyError is raised if the field connot be found.

# File lib/vertica/row.rb, line 36
def fetch(name_or_index)
  @values.fetch(column_index(name_or_index))
end
Also aliased as: []
hash() click to toggle source

@return [Integer] Returns a hash digtest of this object.

# File lib/vertica/row.rb, line 73
def hash
  [row_description, values].hash
end
inspect() click to toggle source

@return [String] Returns a user-consumable string representation of this row.

# File lib/vertica/row.rb, line 78
def inspect
  "#<#{self.class.name}#{@values.inspect}>"
end
to_a() click to toggle source

Returns an array representation of the row. The values will be ordered like the order of the fields in the {#row_description}. @return [Array]

# File lib/vertica/row.rb, line 45
def to_a
  @values
end
to_h(symbolize_keys: false) click to toggle source

Returns a hash representation of this rows, using the name of the fields as keys. @param symbolize_keys [true, false] Set to true to use symbols instead

of strings for the field names.

@return [Hash] @raise [Vertica::Error::DuplicateColumnName] If the row contains multiple

columns with the same name
# 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

Private Instance Methods

column(name_or_index) click to toggle source
# File lib/vertica/row.rb, line 84
def column(name_or_index)
  column_with_index(name_or_index).fetch(0)
end
column_index(name_or_index) click to toggle source
# File lib/vertica/row.rb, line 88
def column_index(name_or_index)
  column_with_index(name_or_index).fetch(1)
end
column_with_index(name_or_index) click to toggle source
# File lib/vertica/row.rb, line 92
def column_with_index(name_or_index)
  @row_description.column_with_index(name_or_index)
end