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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 437fe4302d72a8f1d898659f2f82388dd1e00cfb
4
- data.tar.gz: 4745570fccd99bd783ae52dc747a98a9fcc88708
3
+ metadata.gz: 37453ddf1f6f03f6bc4447ea9c5984829f7e709a
4
+ data.tar.gz: cc2c81547bfdcd23dff2a6f7ffa5da5d1a6933f5
5
5
  SHA512:
6
- metadata.gz: 67aed7638aa7b9b4620293deb64a6a98f1bd04c7fd85174c3be42f461ffb4434925998bfe11cbc9d1c6044e8729625def56cddb3dbbc67b164f76f758a9125d5
7
- data.tar.gz: 1799fe5ba93f17df53403e94533657294a1e85b3344c72cf1fb48f834610c197c5b14bf139c70d33b4eb0dde1399448b58bca6835b4a7bbc719f135de4c67e3c
6
+ metadata.gz: 4ecffc712cd6176b788a409e1a1905a24298424045942901b4f8fbfdf6398f22ecd25edeb1a13e3fcd12278f8401d839426c7b0780e9da23e164de38256498a3
7
+ data.tar.gz: 50156cb27be412acd86f6f3bdbbfe238ed8b5ad1de1de6b04f92ef45a2ce5359acfa7b9eb4da95216cffe22494f822a3a354ee5d23c9b7ec919bd6266f5e7130
data/.gitignore CHANGED
@@ -13,6 +13,9 @@ tmtags
13
13
  ## VIM
14
14
  *.swp
15
15
 
16
+ ## RubyMine
17
+ .idea
18
+
16
19
  ## PROJECT::GENERAL
17
20
  coverage
18
21
  rdoc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- postgres-copy (0.9.1)
4
+ postgres-copy (0.9.2)
5
5
  activerecord (>= 4.0)
6
6
  pg (>= 0.17)
7
7
  rails (>= 4.0)
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) [![Code Climate](https://codeclimate.com/github/diogob/postgres-copy.png)](https://codeclimate.com/github/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
- "DELIMITER '#{options[:delimiter]}' CSV"
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
 
@@ -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 = "0.9.1"
8
+ s.version = "0.9.2"
9
9
 
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.required_ruby_version = ">= 1.9.3"
@@ -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
- end
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
@@ -0,0 +1,2 @@
1
+ id;data
2
+ 1;'test "data" 1'
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 extra_fields;
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.1
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