File tree Expand file tree Collapse file tree 6 files changed +26
-17
lines changed Expand file tree Collapse file tree 6 files changed +26
-17
lines changed Original file line number Diff line number Diff line change 11PATH
22 remote: .
33 specs:
4- postgresql_cursor (0.6.2 )
4+ postgresql_cursor (0.6.3 )
55 activerecord (>= 3.1.0 )
66
77GEM
88 remote: https://rubygems.org/
99 specs:
10- activemodel (5.2.1 )
11- activesupport (= 5.2.1 )
12- activerecord (5.2.1 )
13- activemodel (= 5.2.1 )
14- activesupport (= 5.2.1 )
15- arel (>= 9.0 )
16- activesupport (5.2.1 )
10+ activemodel (6.0.0 )
11+ activesupport (= 6.0.0 )
12+ activerecord (6.0.0 )
13+ activemodel (= 6.0.0 )
14+ activesupport (= 6.0.0 )
15+ activesupport (6.0.0 )
1716 concurrent-ruby (~> 1.0 , >= 1.0.2 )
1817 i18n (>= 0.7 , < 2 )
1918 minitest (~> 5.1 )
2019 tzinfo (~> 1.1 )
21- arel ( 9.0.0 )
22- concurrent-ruby (1.0 .5 )
23- i18n (1.1 .0 )
20+ zeitwerk ( ~> 2.1 , >= 2.1.8 )
21+ concurrent-ruby (1.1 .5 )
22+ i18n (1.6 .0 )
2423 concurrent-ruby (~> 1.0 )
25- minitest (5.11.3 )
26- pg (1.0.0 )
27- rake (12.3.1 )
24+ minitest (5.12.0 )
25+ pg (1.1.4 )
26+ rake (13.0.0 )
2827 thread_safe (0.3.6 )
2928 tzinfo (1.2.5 )
3029 thread_safe (~> 0.1 )
30+ zeitwerk (2.1.10 )
3131
3232PLATFORMS
3333 ruby
@@ -39,4 +39,4 @@ DEPENDENCIES
3939 rake
4040
4141BUNDLED WITH
42- 1.16 .3
42+ 1.17 .3
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ All these methods take an options hash to control things more:
6767 This library uses 1.0 (Optimize for 100% of the result set)
6868 Do not override this value unless you understand it.
6969 with_hold:boolean Keep the cursor "open" even after a commit.
70+ cursor_name:string Give your cursor a name.
7071
7172Notes:
7273
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
13require 'postgresql_cursor/version'
24
35ActiveSupport . on_load :active_record do
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
13# Defines extension to ActiveRecord/AREL to use this library
24module PostgreSQLCursor
35 module ActiveRecord
@@ -12,6 +14,7 @@ module CursorIterators
1214 # block_size: 1..n - The number of rows to fetch per db block fetch
1315 # while: value - Exits loop when block does not return this value.
1416 # until: value - Exits loop when block returns this value.
17+ # cursor_name: string - Allows you to name your cursor.
1518 #
1619 # Example:
1720 # Post.where(user_id:123).each_row { |hash| Post.process(hash) }
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
13################################################################################
24# PostgreSQLCursor: library class provides postgresql cursor for large result
35# set processing. Requires ActiveRecord, but can be adapted to other DBI/ORM libraries.
1012# while: value - Exits loop when block does not return this value.
1113# until: value - Exits loop when block returns this value.
1214# with_hold: boolean - Allows the query to remain open across commit points.
15+ # cursor_name: string - Allows you to name your cursor.
1316#
1417# Exmaples:
1518# PostgreSQLCursor::Cursor.new("select ...").each { |hash| ... }
@@ -245,7 +248,7 @@ def column_types
245248 # Public: Opens (actually, "declares") the cursor. Call this before fetching
246249 def open
247250 set_cursor_tuple_fraction
248- @cursor = SecureRandom . uuid . gsub ( "-" , "" )
251+ @cursor = @options [ :cursor_name ] || SecureRandom . uuid . gsub ( "-" , "" )
249252 hold = @options [ :with_hold ] ? 'with hold ' : ''
250253 @result = @connection . execute ( "declare cursor_#{ @cursor } no scroll cursor #{ hold } for #{ @sql } " )
251254 @block = [ ]
Original file line number Diff line number Diff line change 11module PostgresqlCursor
2- VERSION = "0.6.2.1 "
2+ VERSION = "0.6.3 "
33end
You can’t perform that action at this time.
0 commit comments