pg_csv 0.1.9 → 0.1.10
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/README.md +15 -14
- data/lib/pg_csv.rb +5 -1
- data/lib/pg_csv/version.rb +1 -1
- data/spec/pg_csv_spec.rb +16 -4
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a104e54f42ee73ff35a94124f93e379b69f9669
|
4
|
+
data.tar.gz: f43f120f032bdfc9afc04fe5018fbfd22b8d3e28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b346123dc7faf7b1d0f136c3182deb90bbef3d49f8c8b650ae4ce98e368a9c3e3c5c19052dd9b5194d7e5bbd6ffdd9740c5434f9f5ab977c106d07fd91e39f6
|
7
|
+
data.tar.gz: ea1b05e3bda8aca42f2014df7ba988f87e951f84daf3815af3a951e10b252848e11eb86d17b42377edc0a03c9c45b6e12f270849df631b5f51c1c7f283530d63
|
data/README.md
CHANGED
@@ -17,22 +17,23 @@ PgCsv.new(opts).export(to, opts)
|
|
17
17
|
|
18
18
|
Options:
|
19
19
|
``` ruby
|
20
|
-
:sql
|
21
|
-
:connection
|
22
|
-
:delimiter
|
23
|
-
:header
|
24
|
-
:logger
|
25
|
-
:columns
|
26
|
-
:encoding
|
20
|
+
:sql => "select p.* from users u, projects p where p.user_id = u.id order by email limit 10"
|
21
|
+
:connection => AR.connection
|
22
|
+
:delimiter => ["\t", ",", ]
|
23
|
+
:header => boolean, use pg header for fields?
|
24
|
+
:logger => logger
|
25
|
+
:columns => array of column names, ignore :header option
|
26
|
+
:encoding => encoding (default is pg_default), list of encodings: http://www.postgresql.org/docs/8.4/static/multibyte.html#CHARSET-TABLE
|
27
|
+
:force_quote => boolean, force quotes around all non-NULL data?
|
27
28
|
|
28
|
-
:temp_file
|
29
|
-
:temp_dir
|
29
|
+
:temp_file => boolean, generate throught temp file? final file appears by mv
|
30
|
+
:temp_dir => for :temp_file, ex: '/tmp'
|
30
31
|
|
31
|
-
:type
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
:type => :plain - return full string
|
33
|
+
=> :gzip - save file to gzip
|
34
|
+
=> :stream - save to stream
|
35
|
+
=> :file - just save to file = default
|
36
|
+
=> :yield - return each row to block
|
36
37
|
```
|
37
38
|
|
38
39
|
Examples:
|
data/lib/pg_csv.rb
CHANGED
@@ -133,7 +133,7 @@ class PgCsv
|
|
133
133
|
) TO STDOUT
|
134
134
|
WITH CSV
|
135
135
|
DELIMITER '#{delimiter}'
|
136
|
-
#{use_pg_header? ? 'HEADER' : ''} #{encoding ? "ENCODING '#{encoding}'" : ''}
|
136
|
+
#{use_pg_header? ? 'HEADER' : ''} #{encoding ? "ENCODING '#{encoding}'" : ''} #{force_quote ? "FORCE QUOTE *" : ''}
|
137
137
|
SQL
|
138
138
|
end
|
139
139
|
|
@@ -193,6 +193,10 @@ class PgCsv
|
|
193
193
|
def encoding
|
194
194
|
o(:encoding)
|
195
195
|
end
|
196
|
+
|
197
|
+
def force_quote
|
198
|
+
o(:force_quote)
|
199
|
+
end
|
196
200
|
end
|
197
201
|
|
198
202
|
include Base
|
data/lib/pg_csv/version.rb
CHANGED
data/spec/pg_csv_spec.rb
CHANGED
@@ -63,6 +63,18 @@ describe PgCsv do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
describe "force_quote" do
|
67
|
+
it "force_quote" do
|
68
|
+
PgCsv.new(:sql => @sql).export(@name, :force_quote => true)
|
69
|
+
with_file(@name){|d| d.should == "\"4\",\"5\",\"6\"\n\"1\",\"2\",\"3\"\n"}
|
70
|
+
end
|
71
|
+
|
72
|
+
it "with headers" do
|
73
|
+
PgCsv.new(:sql => @sql).export(@name, :header => true, :force_quote => true)
|
74
|
+
with_file(@name){|d| d.should == "a,b,c\n\"4\",\"5\",\"6\"\n\"1\",\"2\",\"3\"\n"}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
66
78
|
end
|
67
79
|
|
68
80
|
describe "moving options no matter" do
|
@@ -93,14 +105,14 @@ describe PgCsv do
|
|
93
105
|
File.exists?(@name).should == false
|
94
106
|
PgCsv.new(:sql => @sql, :temp_file => true, :temp_dir => tmp_dir).export(@name)
|
95
107
|
with_file(@name){|d| d.should == "4,5,6\n1,2,3\n" }
|
96
|
-
sprintf("%o", File.stat(@name).mode).to_i.should >=
|
108
|
+
sprintf("%o", File.stat(@name).mode).to_i.should >= 100644
|
97
109
|
end
|
98
110
|
|
99
111
|
it "same with gzip" do
|
100
112
|
File.exists?(@name).should == false
|
101
113
|
PgCsv.new(:sql => @sql, :temp_file => true, :temp_dir => tmp_dir, :type => :gzip).export(@name)
|
102
114
|
with_gzfile(@name){|d| d.should == "4,5,6\n1,2,3\n" }
|
103
|
-
sprintf("%o", File.stat(@name).mode).to_i.should >=
|
115
|
+
sprintf("%o", File.stat(@name).mode).to_i.should >= 100644
|
104
116
|
end
|
105
117
|
end
|
106
118
|
|
@@ -109,7 +121,7 @@ describe PgCsv do
|
|
109
121
|
File.exists?(@name).should == false
|
110
122
|
PgCsv.new(:sql => @sql, :type => :gzip).export(@name)
|
111
123
|
with_gzfile(@name){|d| d.should == "4,5,6\n1,2,3\n" }
|
112
|
-
sprintf("%o", File.stat(@name).mode).to_i.should >=
|
124
|
+
sprintf("%o", File.stat(@name).mode).to_i.should >= 100644
|
113
125
|
end
|
114
126
|
|
115
127
|
it "plain export" do
|
@@ -129,7 +141,7 @@ describe PgCsv do
|
|
129
141
|
it "file as default" do
|
130
142
|
PgCsv.new(:sql => @sql, :type => :file).export(@name)
|
131
143
|
with_file(@name){|d| d.should == "4,5,6\n1,2,3\n" }
|
132
|
-
sprintf("%o", File.stat(@name).mode).to_i.should >=
|
144
|
+
sprintf("%o", File.stat(@name).mode).to_i.should >= 100644
|
133
145
|
end
|
134
146
|
|
135
147
|
it "yield export" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makarchev Konstantin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -113,4 +113,10 @@ signing_key:
|
|
113
113
|
specification_version: 4
|
114
114
|
summary: Fast AR/PostgreSQL csv export. Used pg function 'copy to csv'. Effective
|
115
115
|
on millions rows.
|
116
|
-
test_files:
|
116
|
+
test_files:
|
117
|
+
- spec/benchmark/bench.rb
|
118
|
+
- spec/benchmark/raw_bench.rb
|
119
|
+
- spec/pg_csv_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/spec_support.rb
|
122
|
+
- spec/tmp/.gitkeep
|