Class: ActiveRecord::Result

Inherits:
Object show all
Includes:
Enumerable
Defined in:
activerecord/lib/active_record/result.rb

Overview

This class encapsulates a Result returned from calling exec_query on any database connection adapter. For example:

x = ActiveRecord::Base.connection.exec_query('SELECT * FROM foo')
x # => #<ActiveRecord::Result:0xdeadbeef>

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum

Constructor Details

#initialize(columns, rows) ⇒ Result

Returns a new instance of Result.



13
14
15
16
17
# File 'activerecord/lib/active_record/result.rb', line 13

def initialize(columns, rows)
  @columns   = columns
  @rows      = rows
  @hash_rows = nil
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns



11
12
13
# File 'activerecord/lib/active_record/result.rb', line 11

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows



11
12
13
# File 'activerecord/lib/active_record/result.rb', line 11

def rows
  @rows
end

Instance Method Details

#eachObject



19
20
21
# File 'activerecord/lib/active_record/result.rb', line 19

def each
  hash_rows.each { |row| yield row }
end

#to_hashObject



23
24
25
# File 'activerecord/lib/active_record/result.rb', line 23

def to_hash
  hash_rows
end