postgresql_cursor 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +24 -14
- data/postgresql_cursor.gemspec +7 -7
- metadata +16 -9
data/README.rdoc
CHANGED
@@ -9,29 +9,39 @@ For web pages, an application would not want to process a large amount of data,
|
|
9
9
|
Pagination scheme to present it to the users. Background processes sometimes need to generate a large
|
10
10
|
amount of data, and the ActiveRecord approach to load all data into memory is not the best fit here.
|
11
11
|
|
12
|
-
Previous solutions employ pagination to fetch each block,
|
13
|
-
|
14
|
-
the query by using the PostgreSQL cursors.
|
12
|
+
Previous solutions employ pagination to fetch each block, then re-running the query for the next "page".
|
13
|
+
This gem avoids re-executing the query by using PostgreSQL's cursor feature.
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
Julian's benchmarks showed returning instances was a factor of 4 slower than
|
15
|
+
The ActiveRecord methods for the cursor return instances of the model class by default, however you
|
16
|
+
can pass in a block to override this strategy. For instance, returning Hashes instead of AR instances
|
17
|
+
is faster. Julian's benchmarks showed returning instances was a factor of 4 slower than returning a hash.
|
18
|
+
|
19
|
+
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.
|
19
21
|
|
20
22
|
==Installation
|
21
23
|
[sudo] gem install postgresql_cursor
|
22
24
|
|
23
|
-
This does not require Rails to work, just ActiveRecord < 3.0.0 and the 'pg' gem.
|
25
|
+
This does not require Rails to work, just ActiveRecord < 3.0.0 and the 'pg' gem. Rails 3 support is forthcoming.
|
26
|
+
|
27
|
+
You can then configure your Rails application by adding to the config/environment.rb file
|
28
|
+
config.gem 'postgresql_cursor'
|
29
|
+
or require the gem on your non-rails application
|
30
|
+
require 'rubygems'
|
31
|
+
require 'postgresql_cursor'
|
24
32
|
|
25
33
|
==Usage
|
26
34
|
|
27
|
-
|
28
|
-
|
35
|
+
This library is intended to be used via ActiveRecord. It provides two methods on ActiveRecord::Base
|
36
|
+
like the find() method, that will return cursor objects instead of an array of model instances.
|
37
|
+
|
38
|
+
Calling each() the returned cursor will yield a record to the block for each row. It handles a transaction
|
39
|
+
block, open, buffering, and closing the cursor. In this way, it operates like an Array object. Note that
|
40
|
+
it does not implement Enumerable, so no other methods are available.
|
29
41
|
|
30
|
-
|
31
|
-
return each record as a Hash to a procedural block. When each data block is
|
32
|
-
exhausted, it will fetch the next one.
|
42
|
+
* *find_with_cursor*( <i>find options</i>, :cursor=>{<i>cursor options</i>}, &block) returns a cursor for the data matching the find options. It takes an optional block accepting a column=>value hash which returns the object desired via each or next, instead of an instance of the model.
|
33
43
|
|
34
|
-
*find_by_sql_with_cursor* takes a custom SQL statement and returns each row.
|
44
|
+
* *find_by_sql_with_cursor*(<i>select statement</i>, <i>cursor options</i>, &block) takes a custom SQL statement and returns each row as above.
|
35
45
|
|
36
46
|
==Examples
|
37
47
|
|
@@ -39,7 +49,7 @@ exhausted, it will fetch the next one.
|
|
39
49
|
puts row.to_json
|
40
50
|
end
|
41
51
|
|
42
|
-
Account.find_by_sql_with_cursor("select ...", :buffer_size=>1000) do |row|
|
52
|
+
Account.find_by_sql_with_cursor("select ...", :buffer_size=>1000).each do |row|
|
43
53
|
row.process
|
44
54
|
end
|
45
55
|
|
data/postgresql_cursor.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{postgresql_cursor}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
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-
|
12
|
+
s.date = %q{2010-07-29}
|
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 = [
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.homepage = %q{http://github.com/afair/postgresql_cursor}
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
33
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.
|
34
|
+
s.rubygems_version = %q{1.3.7}
|
35
35
|
s.summary = %q{ActiveRecord PostgreSQL Adapter extension for using a cursor to return a large result set}
|
36
36
|
s.test_files = [
|
37
37
|
"test/helper.rb",
|
@@ -42,15 +42,15 @@ Gem::Specification.new do |s|
|
|
42
42
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
43
|
s.specification_version = 3
|
44
44
|
|
45
|
-
if Gem::Version.new(Gem::
|
46
|
-
s.add_runtime_dependency(%q<activerecord>, ["
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
47
47
|
s.add_runtime_dependency(%q<pg>, [">= 0"])
|
48
48
|
else
|
49
|
-
s.add_dependency(%q<activerecord>, ["
|
49
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
50
50
|
s.add_dependency(%q<pg>, [">= 0"])
|
51
51
|
end
|
52
52
|
else
|
53
|
-
s.add_dependency(%q<activerecord>, ["
|
53
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
54
54
|
s.add_dependency(%q<pg>, [">= 0"])
|
55
55
|
end
|
56
56
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgresql_cursor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
+
- 3
|
8
9
|
- 0
|
9
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Allen Fair
|
@@ -14,30 +15,32 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-29 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activerecord
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
|
-
- -
|
27
|
+
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
|
-
-
|
29
|
-
|
30
|
-
- 5
|
31
|
-
version: 2.3.5
|
31
|
+
- 0
|
32
|
+
version: "0"
|
32
33
|
type: :runtime
|
33
34
|
version_requirements: *id001
|
34
35
|
- !ruby/object:Gem::Dependency
|
35
36
|
name: pg
|
36
37
|
prerelease: false
|
37
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
38
40
|
requirements:
|
39
41
|
- - ">="
|
40
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
41
44
|
segments:
|
42
45
|
- 0
|
43
46
|
version: "0"
|
@@ -73,23 +76,27 @@ rdoc_options:
|
|
73
76
|
require_paths:
|
74
77
|
- lib
|
75
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
76
80
|
requirements:
|
77
81
|
- - ">="
|
78
82
|
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
79
84
|
segments:
|
80
85
|
- 0
|
81
86
|
version: "0"
|
82
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
83
89
|
requirements:
|
84
90
|
- - ">="
|
85
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
86
93
|
segments:
|
87
94
|
- 0
|
88
95
|
version: "0"
|
89
96
|
requirements: []
|
90
97
|
|
91
98
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.3.
|
99
|
+
rubygems_version: 1.3.7
|
93
100
|
signing_key:
|
94
101
|
specification_version: 3
|
95
102
|
summary: ActiveRecord PostgreSQL Adapter extension for using a cursor to return a large result set
|