postgres-copy 1.1.1 → 1.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/postgres-copy/acts_as_copy_target.rb +4 -2
- data/postgres-copy.gemspec +1 -1
- data/spec/copy_from_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3cc595142d45d6053c54bac79e0855c4d8136856
|
|
4
|
+
data.tar.gz: 548bbff5d3505a7c9721d0d69f20313072770dd3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e15905d7bcd481f38153decfc9350d0220642c62b35ea7d285293b3ccf2f50fd8cf4e87d1e4bc8c49bcb120e15b6a422b78f05313e3587ca94e0b578561fd28a
|
|
7
|
+
data.tar.gz: 1da873e2f16c582afb38eef9d4dba009067446df3c6835228ec31c1cf2253a8690dd3e716f162a05032b6f0d0becf0d8defcca575cf29c101755c9f651c88935
|
data/Gemfile.lock
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'csv'
|
|
2
|
+
|
|
1
3
|
module PostgresCopy
|
|
2
4
|
module ActsAsCopyTarget
|
|
3
5
|
extend ActiveSupport::Concern
|
|
@@ -84,10 +86,10 @@ module PostgresCopy
|
|
|
84
86
|
while line = io.gets do
|
|
85
87
|
next if line.strip.size == 0
|
|
86
88
|
if block_given?
|
|
87
|
-
row = line.strip
|
|
89
|
+
row = CSV.parse_line(line.strip, {:col_sep => options[:delimiter]})
|
|
88
90
|
yield(row)
|
|
89
91
|
next if row.all?{|f| f.nil? }
|
|
90
|
-
line =
|
|
92
|
+
line = CSV.generate_line(row, {:col_sep => options[:delimiter]})
|
|
91
93
|
end
|
|
92
94
|
connection.raw_connection.put_copy_data line
|
|
93
95
|
end
|
data/postgres-copy.gemspec
CHANGED
data/spec/copy_from_spec.rb
CHANGED
|
@@ -129,6 +129,18 @@ describe "COPY FROM" do
|
|
|
129
129
|
TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test, again'}]
|
|
130
130
|
end
|
|
131
131
|
|
|
132
|
+
it "should import lines with commas inside fields with block given" do
|
|
133
|
+
File.open(File.expand_path('spec/fixtures/comma_inside_field.csv'), 'r') do |file|
|
|
134
|
+
TestModel.copy_from(file) do |row|
|
|
135
|
+
# since our CSV line look like this: {1,"test, again"} we expect only two elements withing row
|
|
136
|
+
row.size.should == 2
|
|
137
|
+
row[0].should == '1'
|
|
138
|
+
row[1].should == 'test, again'
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test, again'}]
|
|
142
|
+
end
|
|
143
|
+
|
|
132
144
|
it "should import with custom null expression from path" do
|
|
133
145
|
TestModel.copy_from File.expand_path('spec/fixtures/special_null_with_header.csv'), :null => 'NULL'
|
|
134
146
|
TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => nil}]
|
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.1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Diogo Biazus
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-03-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pg
|