postgresql_cursor 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f60d787898c546a7c79c8ff6ca3aee03a54793e9a4e3c0798fc39ad6d6ae7a0
4
- data.tar.gz: c175f5708bd1f0b1ba06c005254e7fb513d5ea72f9a7b373f16a42d969cb45eb
3
+ metadata.gz: e5f4a26d515960d1540480268329773c23a4e99453216b5bcd54aba599b27938
4
+ data.tar.gz: 0fa28ed9b5f9e5a981dda5783135c20c120657edc2ef7077bcfee7eeafc8128e
5
5
  SHA512:
6
- metadata.gz: 547822d06073ffc68611179e93332d4840f250fe130d4448a0563986e6e41f9e30f26e3894ba326c4981ad51a44bff77bb326f4e4700f3267f80e6fc4e0008d5
7
- data.tar.gz: 2479ab683e1a598ad18ef5a287106dda78113ab6e745c9ff3bd4eed982c5af9f0a2ad7d1b933b73328229bf39208aa0d25ed513607b06b417742091e7a4c7df6
6
+ metadata.gz: 26ad2f87253cda10a5ebec49b7ed80e44be294460b0a6dea4128a3b6c36e6ad70583921ae1c8cfc89acb00a81e6f744bb0e44c3929adcd97ad360759d2758f8e
7
+ data.tar.gz: 2667b5fee47be190f4cd58f068db030fc7ab34087b1ad56449d2b6722e2205baceae18142ae4692241b1c92cc9382076446283b5807fa9234e70af7799489dba
data/README.md CHANGED
@@ -67,6 +67,7 @@ All these methods take an options hash to control things more:
67
67
  This library uses 1.0 (Optimize for 100% of the result set)
68
68
  Do not override this value unless you understand it.
69
69
  with_hold:boolean Keep the cursor "open" even after a commit.
70
+ cursor_name:string Give your cursor a name.
70
71
 
71
72
  Notes:
72
73
 
@@ -1,12 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'postgresql_cursor/version'
2
- require 'postgresql_cursor/cursor'
3
- require 'postgresql_cursor/active_record/relation/cursor_iterators'
4
- require 'postgresql_cursor/active_record/sql_cursor'
5
- require 'postgresql_cursor/active_record/connection_adapters/postgresql_type_map'
6
4
 
7
- # ActiveRecord 4.x
8
- require 'active_record'
9
- require 'active_record/connection_adapters/postgresql_adapter'
10
- ActiveRecord::Base.extend(PostgreSQLCursor::ActiveRecord::SqlCursor)
11
- ActiveRecord::Relation.send(:include, PostgreSQLCursor::ActiveRecord::Relation::CursorIterators)
12
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, PostgreSQLCursor::ActiveRecord::ConnectionAdapters::PostgreSQLTypeMap)
5
+ ActiveSupport.on_load :active_record do
6
+ require 'postgresql_cursor/cursor'
7
+ require 'postgresql_cursor/active_record/relation/cursor_iterators'
8
+ require 'postgresql_cursor/active_record/sql_cursor'
9
+ require 'postgresql_cursor/active_record/connection_adapters/postgresql_type_map'
10
+
11
+ # ActiveRecord 4.x
12
+ require 'active_record/connection_adapters/postgresql_adapter'
13
+ ActiveRecord::Base.extend(PostgreSQLCursor::ActiveRecord::SqlCursor)
14
+ ActiveRecord::Relation.send(:include, PostgreSQLCursor::ActiveRecord::Relation::CursorIterators)
15
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, PostgreSQLCursor::ActiveRecord::ConnectionAdapters::PostgreSQLTypeMap)
16
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Defines extension to ActiveRecord/AREL to use this library
2
4
  module PostgreSQLCursor
3
5
  module ActiveRecord
@@ -12,6 +14,7 @@ module PostgreSQLCursor
12
14
  # block_size: 1..n - The number of rows to fetch per db block fetch
13
15
  # while: value - Exits loop when block does not return this value.
14
16
  # until: value - Exits loop when block returns this value.
17
+ # cursor_name: string - Allows you to name your cursor.
15
18
  #
16
19
  # Example:
17
20
  # Post.where(user_id:123).each_row { |hash| Post.process(hash) }
@@ -1,4 +1,4 @@
1
- require 'active_record/connection_adapters/postgresql/oid'
1
+ # frozen_string_literal: true
2
2
 
3
3
  ################################################################################
4
4
  # PostgreSQLCursor: library class provides postgresql cursor for large result
@@ -12,6 +12,7 @@ require 'active_record/connection_adapters/postgresql/oid'
12
12
  # while: value - Exits loop when block does not return this value.
13
13
  # until: value - Exits loop when block returns this value.
14
14
  # with_hold: boolean - Allows the query to remain open across commit points.
15
+ # cursor_name: string - Allows you to name your cursor.
15
16
  #
16
17
  # Exmaples:
17
18
  # PostgreSQLCursor::Cursor.new("select ...").each { |hash| ... }
@@ -20,13 +21,6 @@ require 'active_record/connection_adapters/postgresql/oid'
20
21
  # ActiveRecordModel.each_instance_by_sql("select ...") { |model| ... }
21
22
  #
22
23
 
23
-
24
- if ::ActiveRecord::VERSION::MAJOR <= 4
25
- OID = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID
26
- else
27
- OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID
28
- end
29
-
30
24
  module PostgreSQLCursor
31
25
  class Cursor
32
26
  include Enumerable
@@ -240,7 +234,11 @@ module PostgreSQLCursor
240
234
  fmod = @result.fmod i
241
235
  types[fname] = @connection.get_type_map.fetch(ftype, fmod) { |oid, mod|
242
236
  warn "unknown OID: #{fname}(#{oid}) (#{sql})"
243
- OID::Identity.new
237
+ if ::ActiveRecord::VERSION::MAJOR <= 4
238
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Identity.new
239
+ else
240
+ ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Identity.new
241
+ end
244
242
  }
245
243
  end
246
244
 
@@ -250,9 +248,9 @@ module PostgreSQLCursor
250
248
  # Public: Opens (actually, "declares") the cursor. Call this before fetching
251
249
  def open
252
250
  set_cursor_tuple_fraction
253
- @cursor = SecureRandom.uuid.gsub("-","")
251
+ @cursor = @options[:cursor_name] || ("cursor_" + SecureRandom.uuid.gsub("-",""))
254
252
  hold = @options[:with_hold] ? 'with hold ' : ''
255
- @result = @connection.execute("declare cursor_#{@cursor} no scroll cursor #{hold}for #{@sql}")
253
+ @result = @connection.execute("declare #{@cursor} no scroll cursor #{hold}for #{@sql}")
256
254
  @block = []
257
255
  end
258
256
 
@@ -270,7 +268,7 @@ module PostgreSQLCursor
270
268
  # Private: Fetches the next block of rows into @block
271
269
  def fetch_block(block_size=nil)
272
270
  block_size ||= @block_size ||= @options.fetch(:block_size) { 1000 }
273
- @result = @connection.execute("fetch #{block_size} from cursor_#{@cursor}")
271
+ @result = @connection.execute("fetch #{block_size} from #{@cursor}")
274
272
 
275
273
  if @iterate == :each_array
276
274
  @block = @result.each_row.collect {|row| row }
@@ -281,7 +279,7 @@ module PostgreSQLCursor
281
279
 
282
280
  # Public: Closes the cursor
283
281
  def close
284
- @connection.execute("close cursor_#{@cursor}")
282
+ @connection.execute("close #{@cursor}")
285
283
  end
286
284
 
287
285
  # Private: Open transaction unless with_hold option, specified
@@ -1,3 +1,3 @@
1
1
  module PostgresqlCursor
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgresql_cursor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-08 00:00:00.000000000 Z
11
+ date: 2019-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -115,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.7.7
118
+ rubygems_version: 3.0.6
120
119
  signing_key:
121
120
  specification_version: 4
122
121
  summary: ActiveRecord PostgreSQL Adapter extension for using a cursor to return a