Class: Simple::SQL::Decoder::StructRecord

Inherits:
MultiColumns show all
Defined in:
lib/simple/sql/decoder.rb

Constant Summary collapse

@@struct_cache =
{}

Instance Method Summary collapse

Constructor Details

#initialize(connection, result) ⇒ StructRecord

Returns a new instance of StructRecord.



137
138
139
140
141
142
# File 'lib/simple/sql/decoder.rb', line 137

def initialize(connection, result)
  super(connection, result)

  field_names = result.fields.map(&:to_sym)
  @into = @@struct_cache[field_names] ||= Struct.new(*field_names)
end

Instance Method Details

#decode(row) ⇒ Object



144
145
146
147
# File 'lib/simple/sql/decoder.rb', line 144

def decode(row)
  decoded_row = super(row)
  @into.new(*decoded_row)
end