postgres-copy 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +14 -1
- data/lib/postgres-copy/with_temp_table.rb +18 -0
- data/postgres-copy.gemspec +1 -1
- data/spec/postgres-copy/with_temp_table_spec.rb +17 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c9c2751b59517a10e556c5e4cf9cc6c51cafdf1bded29fc3ea493aee37df8f4
|
4
|
+
data.tar.gz: fb386d86afd455b9ebd6b4bbc93f6e2d316b5285fb5e1174ea335284e187c2b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b72e200f779749dbeaf7930835296709ac7c7f8c3b81bab737428c4d221b79032b1fd3996eafe8d2e9280f64f6b811cba1ab456969d6a35b5744cc8d7b6f477
|
7
|
+
data.tar.gz: e916531647bc072804b7a72987ac416674d9a81b6fd48d4c93c57c046e13ab99e172be607a66d09ceea0590a6573c7f9591a0d1b8e795a3eec9858c07f7f14cf
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
postgres-copy (1.
|
4
|
+
postgres-copy (1.7.0)
|
5
5
|
activerecord (>= 5.1)
|
6
6
|
pg (>= 0.17)
|
7
7
|
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
i18n (1.12.0)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
25
|
minitest (5.16.3)
|
26
|
-
pg (1.4.
|
26
|
+
pg (1.4.5)
|
27
27
|
rake (11.2.2)
|
28
28
|
rdoc (6.2.1)
|
29
29
|
rspec (2.99.0)
|
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
|
data/postgres-copy.gemspec
CHANGED
@@ -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.
|
4
|
+
version: 1.7.0
|
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-
|
11
|
+
date: 2022-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -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
|