Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/postgresql_cursor.rb
Overview
Defines extension to ActiveRecord to use this library
Class Method Summary collapse
-
.each_instance_by_sql(sql, options = {}, &block) ⇒ Object
Public: Returns each row as a model instance to the given block As this instantiates a model object, it is slower than each_row_by_sql .
-
.each_row_by_sql(sql, options = {}, &block) ⇒ Object
Public: Returns each row as a hash to the given block.
Class Method Details
.each_instance_by_sql(sql, options = {}, &block) ⇒ Object
Public: Returns each row as a model instance to the given block As this instantiates a model object, it is slower than each_row_by_sql
Paramaters: see each_row_by_sql
Returns the number of rows yielded to the block
141 142 143 144 145 146 147 |
# File 'lib/postgresql_cursor.rb', line 141 def self.each_instance_by_sql(sql, ={}, &block) = {:connection => self.connection}.merge() PostgreSQLCursor.new(sql, ).each do |row| model = instantiate(row) yield model end end |
.each_row_by_sql(sql, options = {}, &block) ⇒ Object
Public: Returns each row as a hash to the given block
sql - Full SQL statement, variables interpolated 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
130 131 132 133 |
# File 'lib/postgresql_cursor.rb', line 130 def self.each_row_by_sql(sql, ={}, &block) = {:connection => self.connection}.merge() PostgreSQLCursor.new(sql, ).each(&block) end |