class RR::TypeCastingCursor

Provides functionality to cast a query result value into the correct ruby type. Requires originating table and column to be known.

Attributes

columns[RW]

A column_name => Column cache

org_cursor[RW]

@return [ResultFetcher] the original cursor

Public Class Methods

new(connection, table, cursor) click to toggle source

Creates a new TypeCastingCursor based on provided database connection and table name for the provided database query cursor

# File lib/rubyrep/type_casting_cursor.rb, line 20
def initialize(connection, table, cursor)
  self.org_cursor = cursor
  self.columns = {}
  connection.columns(table).each {|c| columns[c.name] = c}
end

Public Instance Methods

clear() click to toggle source
# File lib/rubyrep/type_casting_cursor.rb, line 8
def clear; org_cursor.clear end
connection() click to toggle source
# File lib/rubyrep/type_casting_cursor.rb, line 9
def connection; org_cursor.connection end
next?() click to toggle source

Delegate the uninteresting methods to the original cursor

# File lib/rubyrep/type_casting_cursor.rb, line 7
def next?; org_cursor.next? end
next_row() click to toggle source

Reads the next row from the original cursor and returns the row with the type casted row values.

# File lib/rubyrep/type_casting_cursor.rb, line 27
def next_row
  row = org_cursor.next_row
  row.each do |column, value|
    row[column] = connection.connection.fixed_type_cast value, columns[column]
  end
  row
end
options() click to toggle source
# File lib/rubyrep/type_casting_cursor.rb, line 10
def options; org_cursor.options end