postgresql_cursor 0.6.7 → 0.6.9

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: 6b7fec6ed634fe89f563d2fddc6316e3e484e61efa844069064bee889bd8e9a4
4
- data.tar.gz: 79af8640eb56720e25612a4d60c768ab48ab58f77251bac68b42e32c0777c1e5
3
+ metadata.gz: 630053842ad4867acb96172ec30bbb0bf6a2df40f08afe67b19a794394a79dc4
4
+ data.tar.gz: dff4476a6f173f50148e1a18570d91f47b99e08b64dcfb18308f59d8d66bd79e
5
5
  SHA512:
6
- metadata.gz: 31df773065443453d3be8d68917be53ff02f4f354cbb6348b5f1f64f16f7e91dc8eb2de18736fa52a05c5dbe36ef77dea9141e52f856721021cd26d672b02a14
7
- data.tar.gz: e27721566058e269ef75cf6acfaa9b66d06fa50256fc7faff80316a69a55c37bdb46a0e85f31ea478332bca413535a5a302851d4e594efdd147a6812491ad07f
6
+ metadata.gz: fbb48e961a6cc76371639cd5190e48484c350290d14f34882e6ea8e90337b0b948c0abcab1427df85bbeed59979a1e7d1e223f1c4e77a0dd51b81034c0e94208
7
+ data.tar.gz: a7444b6c43a0da1ea29a658852c66f16e1f22b5eef8e93f1a7ca8c24ed7599bdf197c272584ea09dda17d1db498b5f5c8d9b2a4bd0c79169b16c878f9856df0e
data/README.md CHANGED
@@ -88,6 +88,17 @@ Product.each_row.map {|r| r["id"].to_i } #=> [1, 2, 3, ...]
88
88
  Product.each_instance.map {|r| r.id }.each {|id| p id } #=> [1, 2, 3, ...]
89
89
  Product.each_instance.lazy.inject(0) {|sum,r| sum + r.quantity } #=> 499500
90
90
  ```
91
+
92
+ ### PostgreSQLCursor and collection rendering
93
+
94
+ You can render cursor collection, using enumeration as collection attribute.
95
+
96
+ ```ruby
97
+ render partial: "some_partial", collection: Product.each_instance
98
+ render partial: "some_partial", collection: Product.each_row
99
+ render partial: "some_partial", collection: Product.each_hash
100
+ ```
101
+
91
102
  ### Hashes vs. Instances
92
103
 
93
104
  The each_row method returns the Hash of strings for speed (as this allows you to process a lot of rows).
@@ -71,6 +71,12 @@ module PostgreSQLCursor
71
71
  self
72
72
  end
73
73
 
74
+ # ActiveRecord call #size when rendering a collection
75
+ # Define it and return some dummy value
76
+ def size
77
+ -1
78
+ end
79
+
74
80
  # Public: Yields each row of the result set to the passed block
75
81
  #
76
82
  # Yields the row to the block. The row is a hash with symbolized keys.
@@ -229,16 +235,14 @@ module PostgreSQLCursor
229
235
  types = {}
230
236
  fields = @result.fields
231
237
  fields.each_with_index do |fname, i|
232
- ftype = @result.ftype i
233
- fmod = @result.fmod i
234
- types[fname] = @connection.get_type_map.fetch(ftype.to_s, fmod) do |oid, mod|
235
- # warn "unknown OID: #{fname}(#{oid}, #{mod}) (#{sql})"
236
- if ::ActiveRecord::VERSION::MAJOR <= 4
237
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Identity.new
238
- else
239
- ::ActiveRecord::Type::Value.new
240
- end
241
- end
238
+ ftype = @result.ftype(i)
239
+ fmod = @result.fmod(i)
240
+
241
+ # From @netrusov 2023-01-18. This is the same call used in the PostgreSQL Adapter
242
+ types[fname] = @connection.send(:get_oid_type, ftype, fmod, fname)
243
+
244
+ # # From @simi 2023-01-18 (Works as well, used old calling method)
245
+ # types[fname] = @connection.get_type_map.fetch(ftype)
242
246
  end
243
247
 
244
248
  @column_types = types
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostgresqlCursor
4
- VERSION = "0.6.7"
4
+ VERSION = '0.6.9'
5
5
  end
@@ -27,18 +27,14 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- # Remove this for jruby which should use 'activerecord-jdbcpostgresql-adapter'
31
- # spec.add_dependency 'pg'
32
-
33
- spec.add_dependency "activerecord", ">= 3.1.0"
34
- # spec.add_dependency 'activerecord', '~> 3.1.0'
35
- # spec.add_dependency 'activerecord', '~> 4.1.0'
36
- # spec.add_dependency 'activerecord', '~> 5.0.0'
37
- # spec.add_dependency 'activerecord', '~> 6.0.0'
30
+ spec.add_dependency "activerecord", ">= 6.0"
31
+ # spec.add_development_dependency "activerecord", "~> 6.1"
32
+ # spec.add_development_dependency "activerecord", "~> 7.0"
38
33
 
34
+ # PG dependency held back for Jruby. See pg_jruby or jdbc-postgres-adapter gems.
35
+ spec.add_development_dependency "pg" unless RUBY_PLATFORM == "java"
39
36
  spec.add_development_dependency "irb"
40
37
  spec.add_development_dependency "minitest"
41
- spec.add_development_dependency "pg"
42
38
  spec.add_development_dependency "rake"
43
39
  spec.add_development_dependency "appraisal"
44
40
  end
data/test/helper.rb CHANGED
@@ -12,7 +12,8 @@ ActiveRecord::Base.establish_connection(adapter: 'postgresql',
12
12
  class Product < ActiveRecord::Base
13
13
  has_many :prices
14
14
 
15
- # create table records (id serial primary key);
15
+ # create table products (id serial primary key, data varchar);
16
+ # create table prices (id serial primary key, product_id integer references products(id));
16
17
  def self.generate(max=1_000)
17
18
  max.times do |i|
18
19
  connection.execute("insert into products values (#{i+1})")
@@ -150,7 +150,7 @@ class TestPostgresqlCursor < Minitest::Test
150
150
  Product.connection.execute("select kaboom")
151
151
  end
152
152
  rescue => e
153
- assert_match(/PG::InFailedSqlTransaction/, e.message)
153
+ assert_match(/PG::(InFailedSqlTransaction|UndefinedColumn)/, e.message)
154
154
  end
155
155
 
156
156
  def test_batch_exception_in_failed_transaction
@@ -158,7 +158,7 @@ class TestPostgresqlCursor < Minitest::Test
158
158
  Product.connection.execute("select kaboom")
159
159
  end
160
160
  rescue => e
161
- assert_match(/PG::InFailedSqlTransaction/, e.message)
161
+ assert_match(/PG::(InFailedSqlTransaction|UndefinedColumn)/, e.message)
162
162
  end
163
163
 
164
164
  def test_cursor
@@ -225,4 +225,13 @@ class TestPostgresqlCursor < Minitest::Test
225
225
  cursor = Product.first.prices.each_instance
226
226
  refute cursor.instance_variable_get(:@type).loaded?
227
227
  end
228
+
229
+ def test_size
230
+ r = Product.each_instance
231
+ assert_equal -1, r.size
232
+ r = Product.each_hash
233
+ assert_equal -1, r.size
234
+ r = Product.each_row
235
+ assert_equal -1, r.size
236
+ end
228
237
  end
data/test-app/Gemfile CHANGED
@@ -1,15 +1,8 @@
1
1
  # A sample Gemfile
2
2
  source "https://rubygems.org"
3
3
 
4
- gem 'activerecord', '~> 5.2.0'
5
- #gem 'activerecord', '~> 3.2.0'
6
- #gem 'activerecord', '~> 4.0.0'
7
- #gem 'activerecord', '~> 4.1.0'
8
- #gem 'activerecord', '4.1.2.rc1'
4
+ gem "activerecord", "~> 7.0.4.1"
5
+ # gem 'activerecord', '~> 6.1.7.1'
9
6
 
10
- # For testing against Edge Rails
11
- #gem 'activerecord', github: 'rails/rails', branch: 'master'
12
- #gem 'arel', github: 'rails/arel', branch: 'master'
13
-
14
- gem 'pg'
15
- gem 'postgresql_cursor', path:"../"
7
+ gem "pg"
8
+ gem "postgresql_cursor", path: "../"
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.7
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Fair
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-10 00:00:00.000000000 Z
11
+ date: 2024-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,16 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.0
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.0
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: irb
28
+ name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: irb
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pg
56
+ name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubygems_version: 3.4.1
152
+ rubygems_version: 3.5.3
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: ActiveRecord PostgreSQL Adapter extension for using a cursor to return a