Skip to content

Commit

Permalink
Merge branch 'silasdavis-use-connection-of-model'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/postgresql_cursor.rb
  • Loading branch information
afair committed May 14, 2014
2 parents 1659ca7 + 631b9f4 commit fdf53ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ tmtags
## VIM
*.swp

## IntelliJ/Rubymine
.idea

## PROJECT::GENERAL
coverage
rdoc
Expand Down
5 changes: 4 additions & 1 deletion lib/postgresql_cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def set_cursor_tuple_fraction(frac=1.0)

# Defines extension to ActiveRecord to use this library
class ActiveRecord::Base

# Public: Returns each row as a hash to the given block
#
# sql - Full SQL statement, variables interpolated
Expand All @@ -129,6 +128,7 @@ class ActiveRecord::Base
#
# Returns the number of rows yielded to the block
def self.each_row_by_sql(sql, options={}, &block)
options = {:connection => self.connection}.merge(options)
PostgreSQLCursor.new(sql, options).each(&block)
end

Expand All @@ -139,6 +139,7 @@ def self.each_row_by_sql(sql, options={}, &block)
#
# Returns the number of rows yielded to the block
def self.each_instance_by_sql(sql, options={}, &block)
options = {:connection => self.connection}.merge(options)
PostgreSQLCursor.new(sql, options).each do |row|
model = instantiate(row)
yield model
Expand All @@ -160,6 +161,7 @@ class ActiveRecord::Relation
#
# Returns the number of rows yielded to the block
def each_row(options={}, &block)
options = {:connection => self.connection}.merge(options)
PostgreSQLCursor.new(to_sql, options).each(&block)
end

Expand All @@ -169,6 +171,7 @@ def each_row(options={}, &block)
#
# Returns the number of rows yielded to the block
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
Expand Down

0 comments on commit fdf53ab

Please sign in to comment.