Class: ActiveRecord::ConnectionAdapters::AwsDataServiceMysql::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(result, as:, symbolize_keys:, database_timezone:) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
14
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 9

def initialize(result, as:, symbolize_keys:, database_timezone:)
  @result = result
  @as = as
  @symbolize_keys = symbolize_keys
  @database_timezone = database_timezone
end

Instance Method Details

#each(as: @as, symbolize_keys: @symbolize_keys) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 16

def each(as: @as, symbolize_keys: @symbolize_keys)
  return unless @result.records || @result.generated_fields
  raise if @result.records && @result.generated_fields

  @result.lazy.flat_map {|page|
    (page.records || [page.generated_fields]).map {|row|
      row.map {|c| c.is_null ? nil : c.values.compact.first }
    }
  }.each do |row|
    if as == :array
      yield row
    else
      if symbolize_keys
        yield fields.map(&:to_sym).zip(row).to_h
      else
        yield fields.zip(row).to_h
      end
    end
  end
end

#fieldsObject



37
38
39
# File 'lib/active_record/connection_adapters/aws_data_service_mysql/connection.rb', line 37

def fields
  @fields ||= @result. ? @result..map(&:label) : []
end