Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 35 lines (29 sloc) 0.695 kB
cc468d3 @tenderlove exec returns an AR::Result
tenderlove authored
1 module ActiveRecord
2 ###
4c30304 @tenderlove updating the docco for ActiveRecord::Result
tenderlove authored
3 # This class encapsulates a Result returned from calling +exec_query+ on any
0034b78 @smartinez87 Remove extra white spaces on ActiveRecord docs.
smartinez87 authored
4 # database connection adapter. For example:
cc468d3 @tenderlove exec returns an AR::Result
tenderlove authored
5 #
4c30304 @tenderlove updating the docco for ActiveRecord::Result
tenderlove authored
6 # x = ActiveRecord::Base.connection.exec_query('SELECT * FROM foo')
cc468d3 @tenderlove exec returns an AR::Result
tenderlove authored
7 # x # => #<ActiveRecord::Result:0xdeadbeef>
8 class Result
9 include Enumerable
10
11 attr_reader :columns, :rows
12
13 def initialize(columns, rows)
14 @columns = columns
15 @rows = rows
16 @hash_rows = nil
17 end
18
19 def each
20 hash_rows.each { |row| yield row }
21 end
22
59f7780 @tenderlove adjust query counts to be consistent across databases, make sure data…
tenderlove authored
23 def to_hash
24 hash_rows
25 end
26
cc468d3 @tenderlove exec returns an AR::Result
tenderlove authored
27 private
28 def hash_rows
29 @hash_rows ||= @rows.map { |row|
9731c86 @tenderlove AR internals expect a normal hash, otherwise there are serialization …
tenderlove authored
30 Hash[@columns.zip(row)]
cc468d3 @tenderlove exec returns an AR::Result
tenderlove authored
31 }
32 end
33 end
34 end
Something went wrong with that request. Please try again.