Skip to content

Commit

Permalink
Merge branch 'use-connection-of-model' of https://github.com/silasdav…
Browse files Browse the repository at this point in the history
…is/postgresql_cursor into silasdavis-use-connection-of-model
  • Loading branch information
afair committed May 13, 2014
2 parents 8f8705f + b2489e3 commit 631b9f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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
7 changes: 5 additions & 2 deletions 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,7 +161,8 @@ class ActiveRecord::Relation
#
# Returns the number of rows yielded to the block
def each_row(options={}, &block)
PostgreSQLCursor.new(to_sql).each(&block)
options = {:connection => self.connection}.merge(options)
PostgreSQLCursor.new(to_sql, options).each(&block)
end

# Public: Like each_row, but returns an instantiated model object to the block
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)
yield model
Expand Down

0 comments on commit 631b9f4

Please sign in to comment.