postgres-copy 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/postgres-copy/acts_as_copy_target.rb +3 -2
- data/postgres-copy.gemspec +1 -1
- data/spec/copy_from_spec.rb +5 -2
- data/spec/fixtures/semicolon_with_quote.csv +2 -0
- data/spec/spec_helper.rb +2 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37453ddf1f6f03f6bc4447ea9c5984829f7e709a
|
4
|
+
data.tar.gz: cc2c81547bfdcd23dff2a6f7ffa5da5d1a6933f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ecffc712cd6176b788a409e1a1905a24298424045942901b4f8fbfdf6398f22ecd25edeb1a13e3fcd12278f8401d839426c7b0780e9da23e164de38256498a3
|
7
|
+
data.tar.gz: 50156cb27be412acd86f6f3bdbbfe238ed8b5ad1de1de6b04f92ef45a2ce5359acfa7b9eb4da95216cffe22494f822a3a354ee5d23c9b7ec919bd6266f5e7130
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# postgres-copy [![Build Status](https://travis-ci.org/diogob/postgres-copy.
|
1
|
+
# postgres-copy [![Build Status](https://travis-ci.org/diogob/postgres-copy.svg?branch=master)](https://travis-ci.org/diogob/postgres-copy) [![Code Climate](https://codeclimate.com/github/diogob/postgres-copy.svg)](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
|
@@ -43,11 +43,12 @@ module PostgresCopy
|
|
43
43
|
# * You can map fields from the file to different fields in the table using a map in the options hash
|
44
44
|
# * For further details on usage take a look at the README.md
|
45
45
|
def copy_from path_or_io, options = {}
|
46
|
-
options = {:delimiter => ",", :format => :csv, :header => true}.merge(options)
|
46
|
+
options = {:delimiter => ",", :format => :csv, :header => true, :quote => '"'}.merge(options)
|
47
47
|
options_string = if options[:format] == :binary
|
48
48
|
"BINARY"
|
49
49
|
else
|
50
|
-
|
50
|
+
quote = options[:quote] == "'" ? "''" : options[:quote]
|
51
|
+
"DELIMITER '#{options[:delimiter]}' QUOTE '#{quote}' CSV"
|
51
52
|
end
|
52
53
|
io = path_or_io.instance_of?(String) ? File.open(path_or_io, 'r') : path_or_io
|
53
54
|
|
data/postgres-copy.gemspec
CHANGED
data/spec/copy_from_spec.rb
CHANGED
@@ -110,6 +110,9 @@ describe "COPY FROM" do
|
|
110
110
|
{"id"=>3, "data"=>"test data 2", "more_data"=>"9", "other_data"=>nil, "final_data"=>"666"}]
|
111
111
|
end
|
112
112
|
|
113
|
-
|
114
|
-
|
113
|
+
it "should import lines with single quotes" do
|
114
|
+
TestModel.copy_from(File.open(File.expand_path('spec/fixtures/semicolon_with_quote.csv'), 'r'), :delimiter => ";", :quote => "'")
|
115
|
+
TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test "data" 1'}]
|
116
|
+
end
|
115
117
|
|
118
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -24,8 +24,9 @@ RSpec.configure do |config|
|
|
24
24
|
ActiveRecord::Base.connection.execute %{
|
25
25
|
SET client_min_messages TO warning;
|
26
26
|
DROP TABLE IF EXISTS test_models;
|
27
|
-
DROP TABLE IF EXISTS
|
27
|
+
DROP TABLE IF EXISTS test_extended_models;
|
28
28
|
DROP TABLE IF EXISTS reserved_word_models;
|
29
|
+
DROP TABLE IF EXISTS extra_fields;
|
29
30
|
CREATE TABLE test_models (id serial PRIMARY KEY, data text);
|
30
31
|
CREATE TABLE test_extended_models (id serial PRIMARY KEY, data text, more_data text,other_data text,final_data text );
|
31
32
|
CREATE TABLE reserved_word_models (id serial PRIMARY KEY, "select" text, "group" text);
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diogo Biazus
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- spec/fixtures/reserved_words.csv
|
143
143
|
- spec/fixtures/semicolon_with_different_header.csv
|
144
144
|
- spec/fixtures/semicolon_with_header.csv
|
145
|
+
- spec/fixtures/semicolon_with_quote.csv
|
145
146
|
- spec/fixtures/tab_only_data.csv
|
146
147
|
- spec/fixtures/tab_with_different_header.csv
|
147
148
|
- spec/fixtures/tab_with_error.csv
|
@@ -189,6 +190,7 @@ test_files:
|
|
189
190
|
- spec/fixtures/reserved_words.csv
|
190
191
|
- spec/fixtures/semicolon_with_different_header.csv
|
191
192
|
- spec/fixtures/semicolon_with_header.csv
|
193
|
+
- spec/fixtures/semicolon_with_quote.csv
|
192
194
|
- spec/fixtures/tab_only_data.csv
|
193
195
|
- spec/fixtures/tab_with_different_header.csv
|
194
196
|
- spec/fixtures/tab_with_error.csv
|