Class: ActiveRecord::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/postgresql_cursor.rb

Overview

Defines extension to ActiveRecord/AREL to use this library

Instance Method Summary collapse

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(options={}, &block)
  options = {:connection => self.connection}.merge(options)
  PostgreSQLCursor.new(to_sql, options).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(options={}, &block)
  options = {:connection => self.connection}.merge(options)
  PostgreSQLCursor.new(to_sql, options).each(&block)
end