postgres-copy 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +75 -55
- data/README.md +1 -1
- data/lib/postgres-copy/acts_as_copy_target.rb +1 -1
- data/postgres-copy.gemspec +1 -1
- data/spec/copy_from_spec.rb +21 -0
- data/spec/fixtures/comma_with_header_empty_values_at_the_end.csv +4 -0
- data/spec/fixtures/test_extended_model.rb +5 -0
- data/spec/spec_helper.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 437fe4302d72a8f1d898659f2f82388dd1e00cfb
|
4
|
+
data.tar.gz: 4745570fccd99bd783ae52dc747a98a9fcc88708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67aed7638aa7b9b4620293deb64a6a98f1bd04c7fd85174c3be42f461ffb4434925998bfe11cbc9d1c6044e8729625def56cddb3dbbc67b164f76f758a9125d5
|
7
|
+
data.tar.gz: 1799fe5ba93f17df53403e94533657294a1e85b3344c72cf1fb48f834610c197c5b14bf139c70d33b4eb0dde1399448b58bca6835b4a7bbc719f135de4c67e3c
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
postgres-copy (0.9.
|
4
|
+
postgres-copy (0.9.1)
|
5
5
|
activerecord (>= 4.0)
|
6
6
|
pg (>= 0.17)
|
7
7
|
rails (>= 4.0)
|
@@ -10,70 +10,93 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actionmailer (4.
|
14
|
-
actionpack (= 4.
|
15
|
-
actionview (= 4.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
actionmailer (4.2.1)
|
14
|
+
actionpack (= 4.2.1)
|
15
|
+
actionview (= 4.2.1)
|
16
|
+
activejob (= 4.2.1)
|
17
|
+
mail (~> 2.5, >= 2.5.4)
|
18
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
19
|
+
actionpack (4.2.1)
|
20
|
+
actionview (= 4.2.1)
|
21
|
+
activesupport (= 4.2.1)
|
22
|
+
rack (~> 1.6)
|
21
23
|
rack-test (~> 0.6.2)
|
22
|
-
|
23
|
-
|
24
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
25
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
26
|
+
actionview (4.2.1)
|
27
|
+
activesupport (= 4.2.1)
|
24
28
|
builder (~> 3.1)
|
25
29
|
erubis (~> 2.7.0)
|
26
|
-
|
27
|
-
|
30
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
31
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
32
|
+
activejob (4.2.1)
|
33
|
+
activesupport (= 4.2.1)
|
34
|
+
globalid (>= 0.3.0)
|
35
|
+
activemodel (4.2.1)
|
36
|
+
activesupport (= 4.2.1)
|
28
37
|
builder (~> 3.1)
|
29
|
-
activerecord (4.
|
30
|
-
activemodel (= 4.
|
31
|
-
activesupport (= 4.
|
32
|
-
arel (~>
|
33
|
-
activesupport (4.
|
34
|
-
i18n (~> 0.
|
38
|
+
activerecord (4.2.1)
|
39
|
+
activemodel (= 4.2.1)
|
40
|
+
activesupport (= 4.2.1)
|
41
|
+
arel (~> 6.0)
|
42
|
+
activesupport (4.2.1)
|
43
|
+
i18n (~> 0.7)
|
35
44
|
json (~> 1.7, >= 1.7.7)
|
36
45
|
minitest (~> 5.1)
|
37
|
-
thread_safe (~> 0.
|
46
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
38
47
|
tzinfo (~> 1.1)
|
39
|
-
arel (
|
48
|
+
arel (6.0.0)
|
40
49
|
builder (3.2.2)
|
41
50
|
diff-lcs (1.2.5)
|
42
51
|
erubis (2.7.0)
|
52
|
+
globalid (0.3.3)
|
53
|
+
activesupport (>= 4.1.0)
|
43
54
|
hike (1.2.3)
|
44
|
-
i18n (0.
|
55
|
+
i18n (0.7.0)
|
45
56
|
json (1.8.1)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
loofah (2.0.1)
|
58
|
+
nokogiri (>= 1.5.9)
|
59
|
+
mail (2.6.3)
|
60
|
+
mime-types (>= 1.16, < 3)
|
61
|
+
mime-types (2.4.3)
|
62
|
+
mini_portile (0.6.2)
|
63
|
+
minitest (5.5.1)
|
64
|
+
multi_json (1.11.0)
|
65
|
+
nokogiri (1.6.6.2)
|
66
|
+
mini_portile (~> 0.6.0)
|
67
|
+
pg (0.18.1)
|
68
|
+
rack (1.6.0)
|
69
|
+
rack-test (0.6.3)
|
56
70
|
rack (>= 1.0)
|
57
|
-
rails (4.
|
58
|
-
actionmailer (= 4.
|
59
|
-
actionpack (= 4.
|
60
|
-
actionview (= 4.
|
61
|
-
|
62
|
-
|
63
|
-
|
71
|
+
rails (4.2.1)
|
72
|
+
actionmailer (= 4.2.1)
|
73
|
+
actionpack (= 4.2.1)
|
74
|
+
actionview (= 4.2.1)
|
75
|
+
activejob (= 4.2.1)
|
76
|
+
activemodel (= 4.2.1)
|
77
|
+
activerecord (= 4.2.1)
|
78
|
+
activesupport (= 4.2.1)
|
64
79
|
bundler (>= 1.3.0, < 2.0)
|
65
|
-
railties (= 4.
|
66
|
-
sprockets-rails
|
67
|
-
|
68
|
-
|
69
|
-
|
80
|
+
railties (= 4.2.1)
|
81
|
+
sprockets-rails
|
82
|
+
rails-deprecated_sanitizer (1.0.3)
|
83
|
+
activesupport (>= 4.2.0.alpha)
|
84
|
+
rails-dom-testing (1.0.6)
|
85
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
86
|
+
nokogiri (~> 1.6.0)
|
87
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
88
|
+
rails-html-sanitizer (1.0.2)
|
89
|
+
loofah (~> 2.0)
|
90
|
+
railties (4.2.1)
|
91
|
+
actionpack (= 4.2.1)
|
92
|
+
activesupport (= 4.2.1)
|
70
93
|
rake (>= 0.8.7)
|
71
94
|
thor (>= 0.18.1, < 2.0)
|
72
|
-
rake (10.
|
95
|
+
rake (10.4.2)
|
73
96
|
rdoc (4.1.1)
|
74
97
|
json (~> 1.4)
|
75
|
-
responders (
|
76
|
-
railties (>=
|
98
|
+
responders (2.1.0)
|
99
|
+
railties (>= 4.2.0, < 5)
|
77
100
|
rspec (2.99.0)
|
78
101
|
rspec-core (~> 2.99.0)
|
79
102
|
rspec-expectations (~> 2.99.0)
|
@@ -82,22 +105,19 @@ GEM
|
|
82
105
|
rspec-expectations (2.99.0)
|
83
106
|
diff-lcs (>= 1.1.3, < 2.0)
|
84
107
|
rspec-mocks (2.99.1)
|
85
|
-
sprockets (2.12.
|
108
|
+
sprockets (2.12.3)
|
86
109
|
hike (~> 1.2)
|
87
110
|
multi_json (~> 1.0)
|
88
111
|
rack (~> 1.0)
|
89
112
|
tilt (~> 1.1, != 1.3.0)
|
90
|
-
sprockets-rails (2.
|
113
|
+
sprockets-rails (2.2.4)
|
91
114
|
actionpack (>= 3.0)
|
92
115
|
activesupport (>= 3.0)
|
93
|
-
sprockets (
|
116
|
+
sprockets (>= 2.8, < 4.0)
|
94
117
|
thor (0.19.1)
|
95
|
-
thread_safe (0.3.
|
118
|
+
thread_safe (0.3.5)
|
96
119
|
tilt (1.4.1)
|
97
|
-
|
98
|
-
polyglot
|
99
|
-
polyglot (>= 0.3.1)
|
100
|
-
tzinfo (1.2.1)
|
120
|
+
tzinfo (1.2.2)
|
101
121
|
thread_safe (~> 0.1)
|
102
122
|
|
103
123
|
PLATFORMS
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# postgres-copy [![Build Status](https://travis-ci.org/diogob/postgres-copy.png?branch=master)](https://travis-ci.org/diogob/postgres-copy)
|
1
|
+
# postgres-copy [![Build Status](https://travis-ci.org/diogob/postgres-copy.png?branch=master)](https://travis-ci.org/diogob/postgres-copy) [![Code Climate](https://codeclimate.com/github/diogob/postgres-copy.png)](https://codeclimate.com/github/diogob/postgres-copy)
|
2
2
|
|
3
3
|
This Gem will enable your AR models to use the PostgreSQL COPY command to import/export data in CSV format.
|
4
4
|
If you need to tranfer data between a PostgreSQL database and CSV files, the PostgreSQL native CSV parser
|
@@ -82,7 +82,7 @@ module PostgresCopy
|
|
82
82
|
while line = io.gets do
|
83
83
|
next if line.strip.size == 0
|
84
84
|
if block_given?
|
85
|
-
row = line.strip.split(options[:delimiter])
|
85
|
+
row = line.strip.split(options[:delimiter],-1)
|
86
86
|
yield(row)
|
87
87
|
line = row.join(options[:delimiter]) + "\n"
|
88
88
|
end
|
data/postgres-copy.gemspec
CHANGED
data/spec/copy_from_spec.rb
CHANGED
@@ -4,6 +4,7 @@ describe "COPY FROM" do
|
|
4
4
|
before(:each) do
|
5
5
|
ActiveRecord::Base.connection.execute %{
|
6
6
|
TRUNCATE TABLE test_models;
|
7
|
+
TRUNCATE TABLE test_extended_models;
|
7
8
|
SELECT setval('test_models_id_seq', 1, false);
|
8
9
|
}
|
9
10
|
end
|
@@ -90,5 +91,25 @@ describe "COPY FROM" do
|
|
90
91
|
ReservedWordModel.copy_from File.expand_path('spec/fixtures/reserved_words.csv'), :delimiter => "\t"
|
91
92
|
ReservedWordModel.order(:id).map{|r| r.attributes}.should == [{"group"=>"group name", "id"=>1, "select"=>"test select"}]
|
92
93
|
end
|
94
|
+
|
95
|
+
it "should import even last columns have empty values" do
|
96
|
+
TestExtendedModel.copy_from File.expand_path('spec/fixtures/comma_with_header_empty_values_at_the_end.csv')
|
97
|
+
TestExtendedModel.order(:id).map{|r| r.attributes}.should ==
|
98
|
+
[{"id"=>1, "data"=>"test data 1", "more_data"=>nil, "other_data"=>nil, "final_data"=>nil},
|
99
|
+
{"id"=>2, "data"=>"test data 2", "more_data"=>"9", "other_data"=>nil, "final_data"=>nil},
|
100
|
+
{"id"=>3, "data"=>"test data 2", "more_data"=>"9", "other_data"=>nil, "final_data"=>"0"}]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should import even last columns have empty values with block" do
|
104
|
+
TestExtendedModel.copy_from File.expand_path('spec/fixtures/comma_with_header_empty_values_at_the_end.csv') do |row|
|
105
|
+
row[4]="666"
|
106
|
+
end
|
107
|
+
TestExtendedModel.order(:id).map{|r| r.attributes}.should ==
|
108
|
+
[{"id"=>1, "data"=>"test data 1", "more_data"=>nil, "other_data"=>nil, "final_data"=>"666"},
|
109
|
+
{"id"=>2, "data"=>"test data 2", "more_data"=>"9", "other_data"=>nil, "final_data"=>"666"},
|
110
|
+
{"id"=>3, "data"=>"test data 2", "more_data"=>"9", "other_data"=>nil, "final_data"=>"666"}]
|
111
|
+
end
|
112
|
+
|
113
|
+
|
93
114
|
end
|
94
115
|
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'active_record'
|
4
4
|
require 'fixtures/test_model'
|
5
|
+
require 'fixtures/test_extended_model'
|
5
6
|
require 'fixtures/extra_field'
|
6
7
|
require 'fixtures/reserved_word_model'
|
7
8
|
require 'rspec'
|
@@ -26,6 +27,7 @@ RSpec.configure do |config|
|
|
26
27
|
DROP TABLE IF EXISTS extra_fields;
|
27
28
|
DROP TABLE IF EXISTS reserved_word_models;
|
28
29
|
CREATE TABLE test_models (id serial PRIMARY KEY, data text);
|
30
|
+
CREATE TABLE test_extended_models (id serial PRIMARY KEY, data text, more_data text,other_data text,final_data text );
|
29
31
|
CREATE TABLE reserved_word_models (id serial PRIMARY KEY, "select" text, "group" text);
|
30
32
|
CREATE TABLE extra_fields (id serial PRIMARY KEY, data text, created_at timestamp, updated_at timestamp);
|
31
33
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgres-copy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diogo Biazus
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- spec/copy_to_spec.rb
|
136
136
|
- spec/fixtures/2_col_binary_data.dat
|
137
137
|
- spec/fixtures/comma_with_header.csv
|
138
|
+
- spec/fixtures/comma_with_header_empty_values_at_the_end.csv
|
138
139
|
- spec/fixtures/comma_without_header.csv
|
139
140
|
- spec/fixtures/extra_field.rb
|
140
141
|
- spec/fixtures/reserved_word_model.rb
|
@@ -147,6 +148,7 @@ files:
|
|
147
148
|
- spec/fixtures/tab_with_extra_line.csv
|
148
149
|
- spec/fixtures/tab_with_header.csv
|
149
150
|
- spec/fixtures/tab_with_two_lines.csv
|
151
|
+
- spec/fixtures/test_extended_model.rb
|
150
152
|
- spec/fixtures/test_model.rb
|
151
153
|
- spec/spec.opts
|
152
154
|
- spec/spec_helper.rb
|
@@ -169,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
171
|
version: '0'
|
170
172
|
requirements: []
|
171
173
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.4.5
|
173
175
|
signing_key:
|
174
176
|
specification_version: 4
|
175
177
|
summary: Put COPY command functionality in ActiveRecord's model class
|
@@ -180,6 +182,7 @@ test_files:
|
|
180
182
|
- spec/copy_to_spec.rb
|
181
183
|
- spec/fixtures/2_col_binary_data.dat
|
182
184
|
- spec/fixtures/comma_with_header.csv
|
185
|
+
- spec/fixtures/comma_with_header_empty_values_at_the_end.csv
|
183
186
|
- spec/fixtures/comma_without_header.csv
|
184
187
|
- spec/fixtures/extra_field.rb
|
185
188
|
- spec/fixtures/reserved_word_model.rb
|
@@ -192,6 +195,7 @@ test_files:
|
|
192
195
|
- spec/fixtures/tab_with_extra_line.csv
|
193
196
|
- spec/fixtures/tab_with_header.csv
|
194
197
|
- spec/fixtures/tab_with_two_lines.csv
|
198
|
+
- spec/fixtures/test_extended_model.rb
|
195
199
|
- spec/fixtures/test_model.rb
|
196
200
|
- spec/spec.opts
|
197
201
|
- spec/spec_helper.rb
|