postgresql_cursor 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,8 +16,12 @@ The ActiveRecord methods for the cursor return instances of the model class by d
16
16
  can pass in a block to override this strategy. For instance, returning Hashes instead of AR instances
17
17
  is faster. Julian's benchmarks showed returning instances was a factor of 4 slower than returning a hash.
18
18
 
19
+ ActiveRecord v3 has initial support in this release. It is deprecating using the conditions in the find()
20
+ method in favor of Arel scopes and usage. I added a method to Arel for iterate over the results in a buffered
21
+ way.
22
+ Model.scope_methods.each_row { |hash| puts hash.inspect }
23
+
19
24
  NOTE: This gem is intended to replace the 'postgresql-cursor' (with hyphen, not underscore) library.
20
- I also plan on supporing ActiveRecord 3.x in the near future.
21
25
 
22
26
  ==Installation
23
27
  [sudo] gem install postgresql_cursor
@@ -45,6 +49,9 @@ it does not implement Enumerable, so no other methods are available.
45
49
 
46
50
  ==Examples
47
51
 
52
+ # Active Record v3 with Arel scopes. This is the new, preferred method of use
53
+ Account.active.each_row { |hash| puts hash.inspect }
54
+
48
55
  Account.find_with_cursor(:conditions=>["status = ?", 'good']).each do |row|
49
56
  puts row.to_json
50
57
  end
@@ -70,8 +77,7 @@ Allen Fair, allen.fair@gmail.com, http://github.com/afair
70
77
 
71
78
  Thank you to:
72
79
  * Iulian Dogariu, http://github.com/iulianu (Fixes)
73
- * Julian Mehnle, http://www.mehnle.net (Suggestions)
74
-
80
+ * Julian Mehnle, julian@mehnle.net (Suggestions)
75
81
 
76
82
  == Note on Patches/Pull Requests
77
83
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gem.email = "allen.fair@gmail.com"
11
11
  gem.homepage = "http://github.com/afair/postgresql_cursor"
12
12
  gem.authors = ["Allen Fair"]
13
- gem.add_dependency 'activerecord', '<=2.3.5'
13
+ gem.add_dependency 'activerecord'
14
14
  gem.add_dependency 'pg'
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
16
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.1
@@ -1,4 +1,3 @@
1
- gem 'activerecord', '<=2.3.5'
2
1
  require 'active_record'
3
2
 
4
3
  # Class to operate a PostgreSQL cursor to buffer a set of rows, and return single rows for processing.
@@ -103,12 +102,16 @@ class ActiveRecord::Base
103
102
  def find_with_cursor(*args, &block)
104
103
  find_options = args.last.is_a?(Hash) ? args.pop : {}
105
104
  options = find_options.delete(:cursor) || {}
106
- validate_find_options(find_options)
107
- set_readonly_option!(find_options)
108
- sql = construct_finder_sql(find_options)
105
+ #validate_find_options(find_options)
106
+ #set_readonly_option!(find_options)
107
+ #sql = construct_finder_sql(find_options)
108
+
109
+ sql = ActiveRecord::SpawnMethods.apply_finder_options(args.first).to_sql
110
+ puts sql
111
+
109
112
  PostgreSQLCursor.new(sql, options) { |r| block_given? ? yield(r) : instantiate(r) }
110
113
  end
111
-
114
+
112
115
  # Returns a PostgreSQLCursor instance to access the results of the sql
113
116
  # Specify the :cursor=>{...} option to override options for the cursor such has :buffer_size=>n.
114
117
  # Pass an optional block that takes a Hash of the record and returns what you want to return.
@@ -119,3 +122,14 @@ class ActiveRecord::Base
119
122
 
120
123
  end
121
124
  end
125
+
126
+ #Rails 3: add method to use PostgreSQL cursors
127
+ class ActiveRecord::Relation
128
+ @@relation_each_row_seq = 0
129
+
130
+ def each_row(options={}, &block)
131
+ @@relation_each_row_seq += 1
132
+ PostgreSQLCursor.new( to_sql, options).each { |r| block_given? ? yield(r) : instantiate(r) }
133
+ end
134
+
135
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{postgresql_cursor}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Allen Fair"]
12
- s.date = %q{2010-07-29}
12
+ s.date = %q{2010-08-06}
13
13
  s.description = %q{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.}
14
14
  s.email = %q{allen.fair@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgresql_cursor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Allen Fair
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-29 00:00:00 -04:00
18
+ date: 2010-08-06 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency