Class: ActiveRecord::Relation
- Inherits:
-
Object
- Object
- ActiveRecord::Relation
- Defined in:
- lib/postgresql_cursor.rb
Overview
Defines extension to ActiveRecord/AREL to use this library
Instance Method Summary collapse
-
#each_instance(options = {}, &block) ⇒ Object
Public: Like each_row, but returns an instantiated model object to the block.
-
#each_row(options = {}, &block) ⇒ Object
Public: Executes the query, returning each row as a hash to the given block.
Instance Method Details
#each_instance(options = {}, &block) ⇒ Object
Public: Like each_row, but returns an instantiated model object to the block
Paramaters: same as each_row
Returns the number of rows yielded to the block
173 174 175 176 177 178 179 |
# File 'lib/postgresql_cursor.rb', line 173 def each_instance(={}, &block) = {:connection => self.connection}.merge() PostgreSQLCursor.new(to_sql, ).each do |row| model = instantiate(row) block.call model end end |
#each_row(options = {}, &block) ⇒ Object
Public: Executes the query, returning each row as a hash to the given block.
options - Hash to control
fraction: 0.1..1.0 - The cursor_tuple_fraction (default 1.0)
block_size: 1..n - The number of rows to fetch per db block fetch
while: value - Exits loop when block does not return this value.
until: value - Exits loop when block returns this value.
Returns the number of rows yielded to the block
163 164 165 166 |
# File 'lib/postgresql_cursor.rb', line 163 def each_row(={}, &block) = {:connection => self.connection}.merge() PostgreSQLCursor.new(to_sql, ).each(&block) end |