postgres-copy 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: 6eeedb4ef6807baf6f855bfe8d82f56133c66be6
4
- data.tar.gz: 464932914ca5a675064001c803d18ff1dc9fe53d
3
+ metadata.gz: 4c90a9808c66a4ba5412683ba55df5b565b9b855
4
+ data.tar.gz: d3d026898db620ee2544de2f888a73cd6f89a07f
5
5
  SHA512:
6
- metadata.gz: 014a139cab1e421966b374b7eeeff23da62bea3fd4353501b069b4152d55352e6bf851bb544f33ca250fa1de3ba8068356c6097450c56ed1c991712fee785bc1
7
- data.tar.gz: 14e13dc7163ad4c32448d0590278b16b836771da3df6fcec4ee869ded14dcaa62de5667e1274ac6af3e316e3901058c1c432c2b7e5c6ccf2b25ff0e53ca54dfd
6
+ metadata.gz: f7ad7cfb4e702517760953a184cce7859d023f01065877d05f8aa42a08387ea078b4c7a280d19865f1e7f65d840fb386b3467c33daca0d3c10092c05bd891dfa
7
+ data.tar.gz: 64b06032c8b94300c8b5727ac2e93852e3a5836e8c9ef5033435e5dc2c03e6dbfb7362b88d22419a845edaa4fcc17204a4d7d6140b50ab537845048b8f4f71f2
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.3.1
4
4
 
5
5
  branches:
6
6
  only:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- postgres-copy (1.0.0)
4
+ postgres-copy (1.1.0)
5
5
  activerecord (>= 4.0)
6
6
  pg (>= 0.17)
7
7
  rails (>= 4.0)
@@ -10,109 +10,119 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actionmailer (4.2.4)
14
- actionpack (= 4.2.4)
15
- actionview (= 4.2.4)
16
- activejob (= 4.2.4)
13
+ actioncable (5.0.0.1)
14
+ actionpack (= 5.0.0.1)
15
+ nio4r (~> 1.2)
16
+ websocket-driver (~> 0.6.1)
17
+ actionmailer (5.0.0.1)
18
+ actionpack (= 5.0.0.1)
19
+ actionview (= 5.0.0.1)
20
+ activejob (= 5.0.0.1)
17
21
  mail (~> 2.5, >= 2.5.4)
18
- rails-dom-testing (~> 1.0, >= 1.0.5)
19
- actionpack (4.2.4)
20
- actionview (= 4.2.4)
21
- activesupport (= 4.2.4)
22
- rack (~> 1.6)
23
- rack-test (~> 0.6.2)
24
- rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-dom-testing (~> 2.0)
23
+ actionpack (5.0.0.1)
24
+ actionview (= 5.0.0.1)
25
+ activesupport (= 5.0.0.1)
26
+ rack (~> 2.0)
27
+ rack-test (~> 0.6.3)
28
+ rails-dom-testing (~> 2.0)
25
29
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
26
- actionview (4.2.4)
27
- activesupport (= 4.2.4)
30
+ actionview (5.0.0.1)
31
+ activesupport (= 5.0.0.1)
28
32
  builder (~> 3.1)
29
33
  erubis (~> 2.7.0)
30
- rails-dom-testing (~> 1.0, >= 1.0.5)
34
+ rails-dom-testing (~> 2.0)
31
35
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
32
- activejob (4.2.4)
33
- activesupport (= 4.2.4)
34
- globalid (>= 0.3.0)
35
- activemodel (4.2.4)
36
- activesupport (= 4.2.4)
37
- builder (~> 3.1)
38
- activerecord (4.2.4)
39
- activemodel (= 4.2.4)
40
- activesupport (= 4.2.4)
41
- arel (~> 6.0)
42
- activesupport (4.2.4)
36
+ activejob (5.0.0.1)
37
+ activesupport (= 5.0.0.1)
38
+ globalid (>= 0.3.6)
39
+ activemodel (5.0.0.1)
40
+ activesupport (= 5.0.0.1)
41
+ activerecord (5.0.0.1)
42
+ activemodel (= 5.0.0.1)
43
+ activesupport (= 5.0.0.1)
44
+ arel (~> 7.0)
45
+ activesupport (5.0.0.1)
46
+ concurrent-ruby (~> 1.0, >= 1.0.2)
43
47
  i18n (~> 0.7)
44
- json (~> 1.7, >= 1.7.7)
45
48
  minitest (~> 5.1)
46
- thread_safe (~> 0.3, >= 0.3.4)
47
49
  tzinfo (~> 1.1)
48
- arel (6.0.3)
50
+ arel (7.1.4)
49
51
  builder (3.2.2)
52
+ concurrent-ruby (1.0.2)
50
53
  diff-lcs (1.2.5)
51
54
  erubis (2.7.0)
52
- globalid (0.3.6)
55
+ globalid (0.3.7)
53
56
  activesupport (>= 4.1.0)
54
57
  i18n (0.7.0)
55
- json (1.8.1)
58
+ json (1.8.3)
56
59
  loofah (2.0.3)
57
60
  nokogiri (>= 1.5.9)
58
- mail (2.6.3)
59
- mime-types (>= 1.16, < 3)
60
- mime-types (2.6.2)
61
- mini_portile (0.6.2)
62
- minitest (5.8.1)
63
- nokogiri (1.6.6.2)
64
- mini_portile (~> 0.6.0)
65
- pg (0.18.3)
66
- rack (1.6.4)
61
+ mail (2.6.4)
62
+ mime-types (>= 1.16, < 4)
63
+ method_source (0.8.2)
64
+ mime-types (3.1)
65
+ mime-types-data (~> 3.2015)
66
+ mime-types-data (3.2016.0521)
67
+ mini_portile2 (2.1.0)
68
+ minitest (5.10.1)
69
+ nio4r (1.2.1)
70
+ nokogiri (1.6.8.1)
71
+ mini_portile2 (~> 2.1.0)
72
+ pg (0.19.0)
73
+ rack (2.0.1)
67
74
  rack-test (0.6.3)
68
75
  rack (>= 1.0)
69
- rails (4.2.4)
70
- actionmailer (= 4.2.4)
71
- actionpack (= 4.2.4)
72
- actionview (= 4.2.4)
73
- activejob (= 4.2.4)
74
- activemodel (= 4.2.4)
75
- activerecord (= 4.2.4)
76
- activesupport (= 4.2.4)
76
+ rails (5.0.0.1)
77
+ actioncable (= 5.0.0.1)
78
+ actionmailer (= 5.0.0.1)
79
+ actionpack (= 5.0.0.1)
80
+ actionview (= 5.0.0.1)
81
+ activejob (= 5.0.0.1)
82
+ activemodel (= 5.0.0.1)
83
+ activerecord (= 5.0.0.1)
84
+ activesupport (= 5.0.0.1)
77
85
  bundler (>= 1.3.0, < 2.0)
78
- railties (= 4.2.4)
79
- sprockets-rails
80
- rails-deprecated_sanitizer (1.0.3)
81
- activesupport (>= 4.2.0.alpha)
82
- rails-dom-testing (1.0.7)
83
- activesupport (>= 4.2.0.beta, < 5.0)
86
+ railties (= 5.0.0.1)
87
+ sprockets-rails (>= 2.0.0)
88
+ rails-dom-testing (2.0.1)
89
+ activesupport (>= 4.2.0, < 6.0)
84
90
  nokogiri (~> 1.6.0)
85
- rails-deprecated_sanitizer (>= 1.0.1)
86
- rails-html-sanitizer (1.0.2)
91
+ rails-html-sanitizer (1.0.3)
87
92
  loofah (~> 2.0)
88
- railties (4.2.4)
89
- actionpack (= 4.2.4)
90
- activesupport (= 4.2.4)
93
+ railties (5.0.0.1)
94
+ actionpack (= 5.0.0.1)
95
+ activesupport (= 5.0.0.1)
96
+ method_source
91
97
  rake (>= 0.8.7)
92
98
  thor (>= 0.18.1, < 2.0)
93
- rake (10.4.2)
94
- rdoc (4.1.1)
99
+ rake (11.2.2)
100
+ rdoc (4.2.2)
95
101
  json (~> 1.4)
96
- responders (2.1.0)
97
- railties (>= 4.2.0, < 5)
102
+ responders (2.3.0)
103
+ railties (>= 4.2.0, < 5.1)
98
104
  rspec (2.99.0)
99
105
  rspec-core (~> 2.99.0)
100
106
  rspec-expectations (~> 2.99.0)
101
107
  rspec-mocks (~> 2.99.0)
102
- rspec-core (2.99.0)
103
- rspec-expectations (2.99.0)
108
+ rspec-core (2.99.2)
109
+ rspec-expectations (2.99.2)
104
110
  diff-lcs (>= 1.1.3, < 2.0)
105
- rspec-mocks (2.99.1)
106
- sprockets (3.3.5)
111
+ rspec-mocks (2.99.4)
112
+ sprockets (3.7.0)
113
+ concurrent-ruby (~> 1.0)
107
114
  rack (> 1, < 3)
108
- sprockets-rails (2.3.3)
109
- actionpack (>= 3.0)
110
- activesupport (>= 3.0)
111
- sprockets (>= 2.8, < 4.0)
112
- thor (0.19.1)
115
+ sprockets-rails (3.2.0)
116
+ actionpack (>= 4.0)
117
+ activesupport (>= 4.0)
118
+ sprockets (>= 3.0.0)
119
+ thor (0.19.4)
113
120
  thread_safe (0.3.5)
114
121
  tzinfo (1.2.2)
115
122
  thread_safe (~> 0.1)
123
+ websocket-driver (0.6.4)
124
+ websocket-extensions (>= 0.1.0)
125
+ websocket-extensions (0.1.2)
116
126
 
117
127
  PLATFORMS
118
128
  ruby
@@ -120,5 +130,9 @@ PLATFORMS
120
130
  DEPENDENCIES
121
131
  bundler
122
132
  postgres-copy!
133
+ rake (~> 11.2.2)
123
134
  rdoc
124
135
  rspec (~> 2.12)
136
+
137
+ BUNDLED WITH
138
+ 1.13.6
data/README.md CHANGED
@@ -137,6 +137,13 @@ The above extample will always change the value of the first column to "fixed st
137
137
  For each iteration of the block row receives an array with the same order as the columns in the CSV file.
138
138
 
139
139
 
140
+ To specify NULL value you can pass the null option parameter.
141
+
142
+ ```ruby
143
+ User.copy_from "/tmp/users.csv", :null => 'null'
144
+ ```
145
+
146
+
140
147
  To copy a binary formatted data file or IO object you can specify the format as binary
141
148
 
142
149
  ```ruby
@@ -48,7 +48,8 @@ module PostgresCopy
48
48
  "BINARY"
49
49
  else
50
50
  quote = options[:quote] == "'" ? "''" : options[:quote]
51
- "DELIMITER '#{options[:delimiter]}' QUOTE '#{quote}' CSV"
51
+ null = options.key?(:null) ? "NULL '#{options[:null]}'" : ''
52
+ "DELIMITER '#{options[:delimiter]}' QUOTE '#{quote}' #{null} CSV"
52
53
  end
53
54
  io = path_or_io.instance_of?(String) ? File.open(path_or_io, 'r') : path_or_io
54
55
 
@@ -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.0.0"
8
+ s.version = "1.1.0"
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.required_ruby_version = ">= 1.9.3"
11
11
  s.authors = ["Diogo Biazus"]
@@ -27,5 +27,6 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency "bundler"
28
28
  s.add_development_dependency "rdoc"
29
29
  s.add_development_dependency "rspec", "~> 2.12"
30
+ s.add_development_dependency "rake", "~> 11.2.2"
30
31
  end
31
32
 
@@ -124,4 +124,18 @@ describe "COPY FROM" do
124
124
  TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test "data" 1'}]
125
125
  end
126
126
 
127
+ it "should import lines with commas inside fields with default options" do
128
+ TestModel.copy_from(File.open(File.expand_path('spec/fixtures/comma_inside_field.csv'), 'r'))
129
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test, again'}]
130
+ end
131
+
132
+ it "should import with custom null expression from path" do
133
+ TestModel.copy_from File.expand_path('spec/fixtures/special_null_with_header.csv'), :null => 'NULL'
134
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => nil}]
135
+ end
136
+
137
+ it "should import with custom null expression from IO" do
138
+ TestModel.copy_from File.open(File.expand_path('spec/fixtures/special_null_with_header.csv'), 'r'), :null => 'NULL'
139
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => nil}]
140
+ end
127
141
  end
@@ -0,0 +1,2 @@
1
+ id,data
2
+ 1,"test, again"
@@ -0,0 +1,2 @@
1
+ id,data
2
+ 1,NULL
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.0.0
4
+ version: 1.1.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: 2015-09-30 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.12'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 11.2.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 11.2.2
111
125
  description: Now you can use the super fast COPY for import/export data directly from
112
126
  your AR models.
113
127
  email: diogob@gmail.com
@@ -134,6 +148,7 @@ files:
134
148
  - spec/copy_to_binary_spec.rb
135
149
  - spec/copy_to_spec.rb
136
150
  - spec/fixtures/2_col_binary_data.dat
151
+ - spec/fixtures/comma_inside_field.csv
137
152
  - spec/fixtures/comma_with_header.csv
138
153
  - spec/fixtures/comma_with_header_empty_values_at_the_end.csv
139
154
  - spec/fixtures/comma_without_header.csv
@@ -143,6 +158,7 @@ files:
143
158
  - spec/fixtures/semicolon_with_different_header.csv
144
159
  - spec/fixtures/semicolon_with_header.csv
145
160
  - spec/fixtures/semicolon_with_quote.csv
161
+ - spec/fixtures/special_null_with_header.csv
146
162
  - spec/fixtures/tab_only_data.csv
147
163
  - spec/fixtures/tab_with_different_header.csv
148
164
  - spec/fixtures/tab_with_error.csv
@@ -172,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
188
  version: '0'
173
189
  requirements: []
174
190
  rubyforge_project:
175
- rubygems_version: 2.4.5.1
191
+ rubygems_version: 2.5.2
176
192
  signing_key:
177
193
  specification_version: 4
178
194
  summary: Put COPY command functionality in ActiveRecord's model class
@@ -182,6 +198,7 @@ test_files:
182
198
  - spec/copy_to_binary_spec.rb
183
199
  - spec/copy_to_spec.rb
184
200
  - spec/fixtures/2_col_binary_data.dat
201
+ - spec/fixtures/comma_inside_field.csv
185
202
  - spec/fixtures/comma_with_header.csv
186
203
  - spec/fixtures/comma_with_header_empty_values_at_the_end.csv
187
204
  - spec/fixtures/comma_without_header.csv
@@ -191,6 +208,7 @@ test_files:
191
208
  - spec/fixtures/semicolon_with_different_header.csv
192
209
  - spec/fixtures/semicolon_with_header.csv
193
210
  - spec/fixtures/semicolon_with_quote.csv
211
+ - spec/fixtures/special_null_with_header.csv
194
212
  - spec/fixtures/tab_only_data.csv
195
213
  - spec/fixtures/tab_with_different_header.csv
196
214
  - spec/fixtures/tab_with_error.csv