Skip to content

Commit

Permalink
Adds support for Rails/ActiveRecord 3.2.x and up!
Browse files Browse the repository at this point in the history
That wasn't too bad. Since 3.2 is still supported by Rails, we can too.
  • Loading branch information
afair committed Jun 9, 2014
1 parent afaf487 commit f43ade8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def each_instance(options={}, &block)
options = {:connection => self.connection}.merge(options)
options[:symbolize_keys] = false # Must be strings to initiate
PostgreSQLCursor::Cursor.new(to_sql, options).each do |row, column_types|
model = instantiate(row, column_types)
model = ::ActiveRecord::VERSION::MAJOR < 4 ? instantiate(row) : instantiate(row, column_types)
yield model
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/postgresql_cursor/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def cast_types(row)
end

def column_types
return nil if ::ActiveRecord::VERSION::MAJOR < 4
return @column_types if @column_types

types = {}
Expand Down
4 changes: 2 additions & 2 deletions postgresql_cursor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
spec.authors = ["Allen Fair"]
spec.email = ["allen.fair@gmail.com"]
spec.summary = "ActiveRecord PostgreSQL Adapter extension for using a cursor to return a large result set"
spec.description = "PostgreSQL Cursor is an extension to the ActiveRecord PostgreSQLAdapter for very large result sets. It provides a cursor open/fetch/close interface to access data without loading all rows into memory, and instead loads the result rows in \"chunks\" (default of 10_000 rows), buffers them, and returns the rows one at a time."
spec.description = "PostgreSQL Cursor is an extension to the ActiveRecord PostgreSQLAdapter for very large result sets. It provides a cursor open/fetch/close interface to access data without loading all rows into memory, and instead loads the result rows in \"chunks\" (default of 1_000 rows), buffers them, and returns the rows one at a time."
spec.homepage = "http://github.com/afair/postgresql_cursor"
spec.license = "MIT"

Expand All @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

#spec.add_dependency "pg" # Remove this for jruby, which should specify 'activerecord-jdbcpostgresql-adapter'
spec.add_dependency "activerecord", ">= 4.0.0"
spec.add_dependency "activerecord", ">= 3.2.0"

spec.add_development_dependency "rake"
spec.add_development_dependency "minitest"
Expand Down
3 changes: 2 additions & 1 deletion test-app/Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# A sample Gemfile
source "https://rubygems.org"

gem 'activerecord', '~> 3.2.0'
#gem 'activerecord', '~> 4.0.0'
gem 'activerecord', '~> 4.1.0'
#gem 'activerecord', '~> 4.1.0'
#gem 'activerecord', '4.1.2.rc1'

# For testing against Edge Rails
Expand Down
39 changes: 17 additions & 22 deletions test-app/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,33 @@ PATH
remote: /Users/allen/src/postgresql_cursor
specs:
postgresql_cursor (0.5.0)
activerecord (>= 4.0.0)
activerecord (>= 3.2.0)

GEM
remote: https://rubygems.org/
specs:
activemodel (4.1.1)
activesupport (= 4.1.1)
builder (~> 3.1)
activerecord (4.1.1)
activemodel (= 4.1.1)
activesupport (= 4.1.1)
arel (~> 5.0.0)
activesupport (4.1.1)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
builder (3.2.2)
activemodel (3.2.18)
activesupport (= 3.2.18)
builder (~> 3.0.0)
activerecord (3.2.18)
activemodel (= 3.2.18)
activesupport (= 3.2.18)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.18)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
arel (3.0.3)
builder (3.0.4)
i18n (0.6.9)
json (1.8.1)
minitest (5.3.4)
multi_json (1.10.1)
pg (0.17.1)
thread_safe (0.3.4)
tzinfo (1.2.1)
thread_safe (~> 0.1)
tzinfo (0.3.39)

PLATFORMS
ruby

DEPENDENCIES
activerecord (~> 4.1.0)
activerecord (~> 3.2.0)
pg
postgresql_cursor!
4 changes: 2 additions & 2 deletions test-app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def self.generate(max=1_000)

Product.destroy_all
Product.generate
Product.where("id>0").each_row { |r| p r["id"] } # Hash
Product.where("id>0").each_instance { |r| p r.id } # Instance
Product.where("id>0").each_row(block_size:100) { |r| p r["id"] } # Hash
Product.where("id>0").each_instance(block_size:100) { |r| p r.id } # Instance

0 comments on commit f43ade8

Please sign in to comment.