Class: ActiveRecord::Result
- Inherits:
-
Object
- Object
- ActiveRecord::Result
- Includes:
- Enumerable
- Defined in:
- 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
-
#column_types ⇒ Object
readonly
Returns the value of attribute column_types.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #each ⇒ Object
-
#empty? ⇒ Boolean
Returns true if there are no records.
-
#initialize(columns, rows, column_types = {}) ⇒ Result
constructor
A new instance of Result.
- #initialize_copy(other) ⇒ Object
- #last ⇒ Object
- #to_ary ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(columns, rows, column_types = {}) ⇒ Result
Returns a new instance of Result.
13 14 15 16 17 18 |
# File 'lib/active_record/result.rb', line 13 def initialize(columns, rows, column_types = {}) @columns = columns @rows = rows @hash_rows = nil @column_types = column_types end |
Instance Attribute Details
#column_types ⇒ Object (readonly)
Returns the value of attribute column_types.
11 12 13 |
# File 'lib/active_record/result.rb', line 11 def column_types @column_types end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
11 12 13 |
# File 'lib/active_record/result.rb', line 11 def columns @columns end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
11 12 13 |
# File 'lib/active_record/result.rb', line 11 def rows @rows end |
Instance Method Details
#[](idx) ⇒ Object
40 41 42 |
# File 'lib/active_record/result.rb', line 40 def [](idx) hash_rows[idx] end |
#each ⇒ Object
20 21 22 |
# File 'lib/active_record/result.rb', line 20 def each hash_rows.each { |row| yield row } end |
#empty? ⇒ Boolean
Returns true if there are no records.
32 33 34 |
# File 'lib/active_record/result.rb', line 32 def empty? rows.empty? end |
#initialize_copy(other) ⇒ Object
48 49 50 51 52 |
# File 'lib/active_record/result.rb', line 48 def initialize_copy(other) @columns = columns.dup @rows = rows.dup @hash_rows = nil end |
#last ⇒ Object
44 45 46 |
# File 'lib/active_record/result.rb', line 44 def last hash_rows.last end |
#to_ary ⇒ Object
36 37 38 |
# File 'lib/active_record/result.rb', line 36 def to_ary hash_rows end |
#to_hash ⇒ Object
24 25 26 |
# File 'lib/active_record/result.rb', line 24 def to_hash hash_rows end |