postgres-copy 1.6.1 → 1.7.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfe11c5653d850edd47a3df54bcbb83600f820b35a297f05d363b6e89b8b27ff
4
- data.tar.gz: 25a187d205ca18ad00e9a35de9a3fabc400137a56af61fce58eac5f7713491af
3
+ metadata.gz: 9b61e6a83183e87925c1a302b71d04b933beef286eb287db6b51386400cf170c
4
+ data.tar.gz: 6e85f8975d68c208b9e89478ba0d1c8f7ca5d9cf8648c7c0aaba3c078c0b00f7
5
5
  SHA512:
6
- metadata.gz: bf7bdfb2fc14b24ede0973c7e573ed30507c77c205cfe87aa13f9302ad31d988360bcebec83b5ee1c83d266c14d8b42728fb17d5a07c222babc3aab5438562ce
7
- data.tar.gz: b0f085dbbd1fbd684a00d97eda965f7074d52b8e8f0fe07657f33a5a5fcbd9ab4041a71956e640c5b40140c125675f20479044e1aea5b7bea1d1aba9d51e4227
6
+ metadata.gz: 2023840917324d33ad25f64c3041d61d2b1d53478d37363032d32f4b7cedca04309fd8e12e177def36547d06f2805f1e88d526107edc9fc2e947b881d09deef1
7
+ data.tar.gz: bb53b130d33ce95bd02c06a2a4793b2405042c5b2d47da824c73027d4f20394c33d552f8b7ce39dd8e3c320b84c835377fc29bb4321b7902dfc7e4fa6b67433e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- postgres-copy (1.6.1)
4
+ postgres-copy (1.7.1)
5
5
  activerecord (>= 5.1)
6
6
  pg (>= 0.17)
7
7
 
@@ -19,21 +19,30 @@ GEM
19
19
  minitest (>= 5.1)
20
20
  tzinfo (~> 2.0)
21
21
  concurrent-ruby (1.1.10)
22
- diff-lcs (1.4.4)
22
+ diff-lcs (1.5.0)
23
23
  i18n (1.12.0)
24
24
  concurrent-ruby (~> 1.0)
25
- minitest (5.16.3)
26
- pg (1.4.3)
27
- rake (11.2.2)
28
- rdoc (6.2.1)
29
- rspec (2.99.0)
30
- rspec-core (~> 2.99.0)
31
- rspec-expectations (~> 2.99.0)
32
- rspec-mocks (~> 2.99.0)
33
- rspec-core (2.99.2)
34
- rspec-expectations (2.99.2)
35
- diff-lcs (>= 1.1.3, < 2.0)
36
- rspec-mocks (2.99.4)
25
+ minitest (5.17.0)
26
+ pg (1.4.5)
27
+ psych (5.0.1)
28
+ stringio
29
+ rake (12.3.3)
30
+ rdoc (6.5.0)
31
+ psych (>= 4.0.0)
32
+ rspec (3.12.0)
33
+ rspec-core (~> 3.12.0)
34
+ rspec-expectations (~> 3.12.0)
35
+ rspec-mocks (~> 3.12.0)
36
+ rspec-core (3.12.0)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-expectations (3.12.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-mocks (3.12.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-support (3.12.0)
45
+ stringio (3.0.4)
37
46
  tzinfo (2.0.5)
38
47
  concurrent-ruby (~> 1.0)
39
48
 
@@ -43,9 +52,9 @@ PLATFORMS
43
52
  DEPENDENCIES
44
53
  bundler
45
54
  postgres-copy!
46
- rake (~> 11.2.2)
55
+ rake (~> 12.3.3)
47
56
  rdoc
48
- rspec (~> 2.12)
57
+ rspec (~> 3.0)
49
58
 
50
59
  BUNDLED WITH
51
60
  2.2.22
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # postgres-copy
1
+ # postgres-copy
2
2
 
3
3
  ![Ruby](https://github.com/diogob/postgres-copy/workflows/Ruby/badge.svg)
4
4
 
@@ -207,6 +207,19 @@ This is useful for removing byte order marks when matching column headers.
207
207
  User.copy_from "/tmp/users_with_byte_order_mark.csv", :encoding => 'bom|utf-8'
208
208
  ```
209
209
 
210
+ ### Using PostgresCopy::WithTempTable.generate
211
+
212
+ Based on [nfedyashev](https://github.com/nfedyashev)'s [comment](https://github.com/diogob/postgres-copy/issues/51):
213
+
214
+ ```ruby
215
+ PostgresCopy::WithTempTable.generate do |t|
216
+ columns.each do |column_name|
217
+ t.string column_name.to_sym
218
+ end
219
+ end
220
+ ```
221
+
222
+ This auto-generates an id column, but the temp table creation is configurable.
210
223
 
211
224
  ### Using the CSV Responder
212
225
  If you want to make the result of a COPY command available to download this gem provides a CSV responder that, in conjunction with [inherited_resources](https://github.com/josevalim/inherited_resources), is a very powerfull tool. BTW, do not try to use the responder without inherited_resources.
@@ -0,0 +1,18 @@
1
+ module PostgresCopy
2
+ module WithTempTable
3
+ def self.generate(connection = ActiveRecord::Base.connection, base_klass:
4
+ ActiveRecord::Base, temp_table_name: nil, create_table_opts: {id: :bigint})
5
+ raise "You have to pass a table schema definition block!" unless block_given?
6
+ table_name = temp_table_name || "temp_table_#{SecureRandom.hex}"
7
+
8
+ connection.create_table table_name, temporary: true, **create_table_opts do |t|
9
+ yield t
10
+ end
11
+
12
+ klass = Class.new(base_klass) do
13
+ acts_as_copy_target
14
+ self.table_name = table_name
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,7 +5,7 @@ $:.unshift lib unless $:.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "postgres-copy"
8
- s.version = "1.6.1"
8
+ s.version = "1.7.1"
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.required_ruby_version = ">= 1.9.3"
11
11
  s.authors = ["Diogo Biazus"]
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency "activerecord", '>= 5.1'
25
25
  s.add_development_dependency "bundler"
26
26
  s.add_development_dependency "rdoc"
27
- s.add_development_dependency "rspec", "~> 2.12"
28
- s.add_development_dependency "rake", "~> 11.2.2"
27
+ s.add_development_dependency "rspec", "~> 3.0"
28
+ s.add_development_dependency "rake", "~> 12.3.3"
29
29
  end
30
30
 
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'postgres-copy/with_temp_table'
3
+
4
+ describe '.generate' do
5
+ subject(:generate) {
6
+ PostgresCopy::WithTempTable.generate do |t|
7
+ t.string :data
8
+ end
9
+ }
10
+
11
+ it {
12
+ generate.copy_from 'spec/fixtures/comma_with_header.csv'
13
+ data = generate.all.first
14
+ expect(data.id).to eq(1)
15
+ expect(data.data).to eq('test data 1')
16
+ }
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres-copy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diogo Biazus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -72,28 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.12'
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.12'
82
+ version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 11.2.2
89
+ version: 12.3.3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 11.2.2
96
+ version: 12.3.3
97
97
  description: Now you can use the super fast COPY for import/export data directly from
98
98
  your AR models.
99
99
  email: diogob@gmail.com
@@ -113,6 +113,7 @@ files:
113
113
  - lib/postgres-copy.rb
114
114
  - lib/postgres-copy/acts_as_copy_target.rb
115
115
  - lib/postgres-copy/csv_responder.rb
116
+ - lib/postgres-copy/with_temp_table.rb
116
117
  - postgres-copy.gemspec
117
118
  - spec/copy_from_binary_spec.rb
118
119
  - spec/copy_from_spec.rb
@@ -147,6 +148,7 @@ files:
147
148
  - spec/fixtures/tab_with_two_lines.tsv
148
149
  - spec/fixtures/test_extended_model.rb
149
150
  - spec/fixtures/test_model.rb
151
+ - spec/postgres-copy/with_temp_table_spec.rb
150
152
  - spec/spec.opts
151
153
  - spec/spec_helper.rb
152
154
  homepage: http://github.com/diogob/postgres-copy