postgres-copy 0.6.0 → 0.7.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ada774ac0dab27f58b81246ede246219546bd6f
4
+ data.tar.gz: 7a7c83893ebe10c82501611fb72850b2d345946c
5
+ SHA512:
6
+ metadata.gz: 4ce6dc87b7bd78813b40cc6c566c1d2a760a4d8dee7e4cf0dca707d826b9982010dfe32cc851b9c18f4329d16a16cba614feb3b6f49beb561e0cfdb8cb5a4a70
7
+ data.tar.gz: 62e04ba3a0368057d4c53ab8b5f0b730e994c26c54454d21cedd996525309667a2844b84ded5dc12a0dac5cd80b415b5605bcc1e8d22b71ab42ecdf7f1ab1ab3
data/Gemfile.lock CHANGED
@@ -1,84 +1,75 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- postgres-copy (0.6.0)
5
- activerecord (>= 3.0.0)
4
+ postgres-copy (0.7.0)
5
+ activerecord (~> 4.0)
6
6
  pg
7
- rails (>= 3.0.0)
7
+ rails (~> 4.0)
8
8
  responders
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actionmailer (3.2.13)
14
- actionpack (= 3.2.13)
13
+ actionmailer (4.0.0)
14
+ actionpack (= 4.0.0)
15
15
  mail (~> 2.5.3)
16
- actionpack (3.2.13)
17
- activemodel (= 3.2.13)
18
- activesupport (= 3.2.13)
19
- builder (~> 3.0.0)
16
+ actionpack (4.0.0)
17
+ activesupport (= 4.0.0)
18
+ builder (~> 3.1.0)
20
19
  erubis (~> 2.7.0)
21
- journey (~> 1.0.4)
22
- rack (~> 1.4.5)
23
- rack-cache (~> 1.2)
24
- rack-test (~> 0.6.1)
25
- sprockets (~> 2.2.1)
26
- activemodel (3.2.13)
27
- activesupport (= 3.2.13)
28
- builder (~> 3.0.0)
29
- activerecord (3.2.13)
30
- activemodel (= 3.2.13)
31
- activesupport (= 3.2.13)
32
- arel (~> 3.0.2)
33
- tzinfo (~> 0.3.29)
34
- activeresource (3.2.13)
35
- activemodel (= 3.2.13)
36
- activesupport (= 3.2.13)
37
- activesupport (3.2.13)
38
- i18n (= 0.6.1)
39
- multi_json (~> 1.0)
40
- arel (3.0.2)
41
- builder (3.0.4)
20
+ rack (~> 1.5.2)
21
+ rack-test (~> 0.6.2)
22
+ activemodel (4.0.0)
23
+ activesupport (= 4.0.0)
24
+ builder (~> 3.1.0)
25
+ activerecord (4.0.0)
26
+ activemodel (= 4.0.0)
27
+ activerecord-deprecated_finders (~> 1.0.2)
28
+ activesupport (= 4.0.0)
29
+ arel (~> 4.0.0)
30
+ activerecord-deprecated_finders (1.0.3)
31
+ activesupport (4.0.0)
32
+ i18n (~> 0.6, >= 0.6.4)
33
+ minitest (~> 4.2)
34
+ multi_json (~> 1.3)
35
+ thread_safe (~> 0.1)
36
+ tzinfo (~> 0.3.37)
37
+ arel (4.0.0)
38
+ atomic (1.1.13)
39
+ builder (3.1.4)
42
40
  diff-lcs (1.1.3)
43
41
  erubis (2.7.0)
44
- hike (1.2.2)
45
- i18n (0.6.1)
46
- journey (1.0.4)
42
+ hike (1.2.3)
43
+ i18n (0.6.5)
47
44
  json (1.7.6)
48
45
  mail (2.5.4)
49
46
  mime-types (~> 1.16)
50
47
  treetop (~> 1.4.8)
51
48
  mime-types (1.23)
52
- multi_json (1.7.3)
53
- pg (0.15.1)
49
+ minitest (4.7.5)
50
+ multi_json (1.7.9)
51
+ pg (0.16.0)
54
52
  polyglot (0.3.3)
55
- rack (1.4.5)
56
- rack-cache (1.2)
57
- rack (>= 0.4)
58
- rack-ssl (1.3.3)
59
- rack
53
+ rack (1.5.2)
60
54
  rack-test (0.6.2)
61
55
  rack (>= 1.0)
62
- rails (3.2.13)
63
- actionmailer (= 3.2.13)
64
- actionpack (= 3.2.13)
65
- activerecord (= 3.2.13)
66
- activeresource (= 3.2.13)
67
- activesupport (= 3.2.13)
68
- bundler (~> 1.0)
69
- railties (= 3.2.13)
70
- railties (3.2.13)
71
- actionpack (= 3.2.13)
72
- activesupport (= 3.2.13)
73
- rack-ssl (~> 1.3.2)
56
+ rails (4.0.0)
57
+ actionmailer (= 4.0.0)
58
+ actionpack (= 4.0.0)
59
+ activerecord (= 4.0.0)
60
+ activesupport (= 4.0.0)
61
+ bundler (>= 1.3.0, < 2.0)
62
+ railties (= 4.0.0)
63
+ sprockets-rails (~> 2.0.0)
64
+ railties (4.0.0)
65
+ actionpack (= 4.0.0)
66
+ activesupport (= 4.0.0)
74
67
  rake (>= 0.8.7)
75
- rdoc (~> 3.4)
76
- thor (>= 0.14.6, < 2.0)
77
- rake (10.0.4)
68
+ thor (>= 0.18.1, < 2.0)
69
+ rake (10.1.0)
78
70
  rdoc (3.12)
79
71
  json (~> 1.4)
80
- responders (0.9.3)
81
- railties (~> 3.1)
72
+ responders (0.6.5)
82
73
  rspec (2.12.0)
83
74
  rspec-core (~> 2.12.0)
84
75
  rspec-expectations (~> 2.12.0)
@@ -87,14 +78,20 @@ GEM
87
78
  rspec-expectations (2.12.1)
88
79
  diff-lcs (~> 1.1.3)
89
80
  rspec-mocks (2.12.2)
90
- sprockets (2.2.2)
81
+ sprockets (2.10.0)
91
82
  hike (~> 1.2)
92
83
  multi_json (~> 1.0)
93
84
  rack (~> 1.0)
94
85
  tilt (~> 1.1, != 1.3.0)
86
+ sprockets-rails (2.0.0)
87
+ actionpack (>= 3.0)
88
+ activesupport (>= 3.0)
89
+ sprockets (~> 2.8)
95
90
  thor (0.18.1)
91
+ thread_safe (0.1.2)
92
+ atomic
96
93
  tilt (1.4.1)
97
- treetop (1.4.12)
94
+ treetop (1.4.14)
98
95
  polyglot
99
96
  polyglot (>= 0.3.1)
100
97
  tzinfo (0.3.37)
@@ -11,9 +11,9 @@ module ActiveRecord
11
11
 
12
12
  if path
13
13
  raise "You have to choose between exporting to a file or receiving the lines inside a block" if block_given?
14
- connection.execute "COPY (#{self.scoped.to_sql}) TO #{sanitize(path)} WITH #{options_string}"
14
+ connection.execute "COPY (#{self.all.to_sql}) TO #{sanitize(path)} WITH #{options_string}"
15
15
  else
16
- connection.execute "COPY (#{self.scoped.to_sql}) TO STDOUT WITH #{options_string}"
16
+ connection.execute "COPY (#{self.all.to_sql}) TO STDOUT WITH #{options_string}"
17
17
  while line = connection.raw_connection.get_copy_data do
18
18
  yield(line) if block_given?
19
19
  end
@@ -5,10 +5,10 @@ $:.unshift lib unless $:.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "postgres-copy"
8
- s.version = "0.6.0"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.platform = Gem::Platform::RUBY
11
- s.required_ruby_version = ">= 1.8.7"
11
+ s.required_ruby_version = ">= 1.9.3"
12
12
  s.authors = ["Diogo Biazus"]
13
13
  s.date = "2013-01-31"
14
14
  s.description = "Now you can use the super fast COPY for import/export data directly from your AR models."
@@ -23,8 +23,8 @@ Gem::Specification.new do |s|
23
23
  s.summary = "Put COPY command functionality in ActiveRecord's model class"
24
24
 
25
25
  s.add_dependency "pg"
26
- s.add_dependency "activerecord", '>= 3.0.0'
27
- s.add_dependency "rails", '>= 3.0.0'
26
+ s.add_dependency "activerecord", '~> 4.0'
27
+ s.add_dependency "rails", '~> 4.0'
28
28
  s.add_dependency "responders"
29
29
  s.add_development_dependency "bundler"
30
30
  s.add_development_dependency "rdoc"
@@ -10,12 +10,12 @@ describe "COPY FROM BINARY" do
10
10
 
11
11
  it "should import from file if path is passed without field_map" do
12
12
  TestModel.pg_copy_from File.expand_path('spec/fixtures/2_col_binary_data.dat'), :format => :binary, columns: [:id, :data]
13
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'text'}]
13
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'text'}]
14
14
  end
15
15
 
16
16
  it "should import from file if columns are not specified" do
17
17
  TestModel.pg_copy_from File.expand_path('spec/fixtures/2_col_binary_data.dat'), :format => :binary
18
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'text'}]
18
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'text'}]
19
19
  end
20
20
 
21
21
  end
@@ -10,29 +10,29 @@ describe "COPY FROM" do
10
10
 
11
11
  it "should import from file if path is passed without field_map" do
12
12
  TestModel.pg_copy_from File.expand_path('spec/fixtures/comma_with_header.csv')
13
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
13
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
14
14
  end
15
15
 
16
16
  it "should import from IO without field_map" do
17
17
  TestModel.pg_copy_from File.open(File.expand_path('spec/fixtures/comma_with_header.csv'), 'r')
18
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
18
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
19
19
  end
20
20
 
21
21
  it "should import with custom delimiter from path" do
22
22
  TestModel.pg_copy_from File.expand_path('spec/fixtures/semicolon_with_header.csv'), :delimiter => ';'
23
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
23
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
24
24
  end
25
25
 
26
26
  it "should import with custom delimiter from IO" do
27
27
  TestModel.pg_copy_from File.open(File.expand_path('spec/fixtures/semicolon_with_header.csv'), 'r'), :delimiter => ';'
28
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
28
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
29
29
  end
30
30
 
31
31
  it "should import and allow changes in block" do
32
32
  TestModel.pg_copy_from(File.open(File.expand_path('spec/fixtures/comma_with_header.csv'), 'r')) do |row|
33
33
  row[1] = 'changed this data'
34
34
  end
35
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'changed this data'}]
35
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'changed this data'}]
36
36
  end
37
37
 
38
38
  it "should import 2 lines and allow changes in block" do
@@ -45,37 +45,37 @@ describe "COPY FROM" do
45
45
 
46
46
  it "should be able to copy from using custom set of columns" do
47
47
  TestModel.pg_copy_from(File.open(File.expand_path('spec/fixtures/tab_only_data.csv'), 'r'), :delimiter => "\t", :columns => ["data"])
48
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
48
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
49
49
  end
50
50
 
51
51
  it "default set of columns should be all table columns minus [id, created_at, updated_at]" do
52
52
  ExtraField.pg_copy_from(File.open(File.expand_path('spec/fixtures/comma_with_header.csv'), 'r'))
53
- ExtraField.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1', 'created_at' => nil, 'updated_at' => nil}]
53
+ ExtraField.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1', 'created_at' => nil, 'updated_at' => nil}]
54
54
  end
55
55
 
56
56
  it "should not expect a header when :header is false" do
57
57
  TestModel.pg_copy_from(File.open(File.expand_path('spec/fixtures/comma_without_header.csv'), 'r'), :header => false, :columns => [:id,:data])
58
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
58
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
59
59
  end
60
60
 
61
61
  it "should use the table name given by :table" do
62
62
  ActiveRecord::Base.pg_copy_from(File.open(File.expand_path('spec/fixtures/comma_without_header.csv'), 'r'), :header => false, :columns => [:id,:data], :table => "test_models")
63
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
63
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
64
64
  end
65
65
 
66
66
  it "should be able to map the header in the file to diferent column names" do
67
67
  TestModel.pg_copy_from(File.open(File.expand_path('spec/fixtures/tab_with_different_header.csv'), 'r'), :delimiter => "\t", :map => {'cod' => 'id', 'info' => 'data'})
68
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
68
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
69
69
  end
70
70
 
71
71
  it "should be able to map the header in the file to diferent column names with custom delimiter" do
72
72
  TestModel.pg_copy_from(File.open(File.expand_path('spec/fixtures/semicolon_with_different_header.csv'), 'r'), :delimiter => ';', :map => {'cod' => 'id', 'info' => 'data'})
73
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
73
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
74
74
  end
75
75
 
76
76
  it "should ignore empty lines" do
77
77
  TestModel.pg_copy_from(File.open(File.expand_path('spec/fixtures/tab_with_extra_line.csv'), 'r'), :delimiter => "\t")
78
- TestModel.order(:id).all.map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
78
+ TestModel.order(:id).map{|r| r.attributes}.should == [{'id' => 1, 'data' => 'test data 1'}]
79
79
  end
80
80
 
81
81
  #we should implement this later
@@ -83,12 +83,12 @@ describe "COPY FROM" do
83
83
  #lambda do
84
84
  #TestModel.pg_copy_from(File.open(File.expand_path('spec/fixtures/tab_with_error.csv'), 'r'))
85
85
  #end.should raise_error
86
- #TestModel.order(:id).all.map{|r| r.attributes}.should == []
86
+ #TestModel.order(:id).map{|r| r.attributes}.should == []
87
87
  #end
88
88
 
89
89
  it "should copy from even when table fields need identifier quoting" do
90
90
  ReservedWordModel.pg_copy_from File.expand_path('spec/fixtures/reserved_words.csv'), :delimiter => "\t"
91
- ReservedWordModel.order(:id).all.map{|r| r.attributes}.should == [{"group"=>"group name", "id"=>1, "select"=>"test select"}]
91
+ ReservedWordModel.order(:id).map{|r| r.attributes}.should == [{"group"=>"group name", "id"=>1, "select"=>"test select"}]
92
92
  end
93
93
  end
94
94
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres-copy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
5
- prerelease:
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Diogo Biazus
@@ -14,103 +13,90 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: pg
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activerecord
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: 3.0.0
33
+ version: '4.0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: 3.0.0
40
+ version: '4.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rails
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ~>
52
46
  - !ruby/object:Gem::Version
53
- version: 3.0.0
47
+ version: '4.0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ~>
60
53
  - !ruby/object:Gem::Version
61
- version: 3.0.0
54
+ version: '4.0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: responders
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: bundler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rdoc
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
@@ -167,29 +152,46 @@ files:
167
152
  - spec/spec_helper.rb
168
153
  homepage: http://github.com/diogob/postgres-copy
169
154
  licenses: []
155
+ metadata: {}
170
156
  post_install_message:
171
157
  rdoc_options: []
172
158
  require_paths:
173
159
  - lib
174
160
  required_ruby_version: !ruby/object:Gem::Requirement
175
- none: false
176
161
  requirements:
177
- - - ! '>='
162
+ - - '>='
178
163
  - !ruby/object:Gem::Version
179
- version: 1.8.7
164
+ version: 1.9.3
180
165
  required_rubygems_version: !ruby/object:Gem::Requirement
181
- none: false
182
166
  requirements:
183
- - - ! '>='
167
+ - - '>='
184
168
  - !ruby/object:Gem::Version
185
169
  version: '0'
186
- segments:
187
- - 0
188
- hash: -1552817411289584753
189
170
  requirements: []
190
171
  rubyforge_project:
191
- rubygems_version: 1.8.25
172
+ rubygems_version: 2.0.7
192
173
  signing_key:
193
- specification_version: 3
174
+ specification_version: 4
194
175
  summary: Put COPY command functionality in ActiveRecord's model class
195
- test_files: []
176
+ test_files:
177
+ - spec/fixtures/2_col_binary_data.dat
178
+ - spec/fixtures/comma_with_header.csv
179
+ - spec/fixtures/comma_without_header.csv
180
+ - spec/fixtures/extra_field.rb
181
+ - spec/fixtures/reserved_word_model.rb
182
+ - spec/fixtures/reserved_words.csv
183
+ - spec/fixtures/semicolon_with_different_header.csv
184
+ - spec/fixtures/semicolon_with_header.csv
185
+ - spec/fixtures/tab_only_data.csv
186
+ - spec/fixtures/tab_with_different_header.csv
187
+ - spec/fixtures/tab_with_error.csv
188
+ - spec/fixtures/tab_with_extra_line.csv
189
+ - spec/fixtures/tab_with_header.csv
190
+ - spec/fixtures/tab_with_two_lines.csv
191
+ - spec/fixtures/test_model.rb
192
+ - spec/pg_copy_from_binary_spec.rb
193
+ - spec/pg_copy_from_spec.rb
194
+ - spec/pg_copy_to_binary_spec.rb
195
+ - spec/pg_copy_to_spec.rb
196
+ - spec/spec.opts
197
+ - spec/spec_helper.rb