pg_data_encoder 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -63,7 +63,15 @@ or
|
|
63
63
|
|
64
64
|
## Added type support
|
65
65
|
|
66
|
-
Currently it supports
|
66
|
+
Currently it supports
|
67
|
+
|
68
|
+
* Integers
|
69
|
+
* Strings
|
70
|
+
* Hstore
|
71
|
+
* Boolean
|
72
|
+
* Floats (double precision)
|
73
|
+
* Timestamp
|
74
|
+
* Array (integer and string single dimension)
|
67
75
|
|
68
76
|
## Contributing
|
69
77
|
|
@@ -19,7 +19,7 @@ module PgDataEncoder
|
|
19
19
|
|
20
20
|
def close
|
21
21
|
@closed = true
|
22
|
-
@io.write([-1].pack("n"))
|
22
|
+
@io.write([-1].pack("n")) rescue raise Exception.new("No rows have been added to the encoder!")
|
23
23
|
@io.rewind
|
24
24
|
end
|
25
25
|
|
@@ -60,6 +60,14 @@ module PgDataEncoder
|
|
60
60
|
buf = [field].pack("G")
|
61
61
|
io.write([buf.bytesize].pack("N"))
|
62
62
|
io.write(buf)
|
63
|
+
when true
|
64
|
+
buf = [1].pack("C")
|
65
|
+
io.write([1].pack("N"))
|
66
|
+
io.write(buf)
|
67
|
+
when false
|
68
|
+
buf = [0].pack("C")
|
69
|
+
io.write([1].pack("N"))
|
70
|
+
io.write(buf)
|
63
71
|
when nil
|
64
72
|
io.write([-1].pack("N"))
|
65
73
|
when String
|
data/spec/errors_spec.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "throwing errors" do
|
4
|
+
it "should raise an error when no rows have been added to the encoder" do
|
5
|
+
encoder = PgDataEncoder::EncodeForCopy.new
|
6
|
+
expect { encoder.close }.to raise_error
|
7
|
+
end
|
8
|
+
end
|
Binary file
|
Binary file
|
@@ -27,6 +27,30 @@ describe "generating data" do
|
|
27
27
|
str.should == existing_data
|
28
28
|
end
|
29
29
|
|
30
|
+
it 'should encode TrueClass data correctly' do
|
31
|
+
encoder = PgDataEncoder::EncodeForCopy.new
|
32
|
+
encoder.add [true]
|
33
|
+
encoder.close
|
34
|
+
io = encoder.get_io
|
35
|
+
existing_data = filedata("trueclass.dat")
|
36
|
+
str = io.read
|
37
|
+
io.class.name.should == "StringIO"
|
38
|
+
str.force_encoding("ASCII-8BIT")
|
39
|
+
str.should == existing_data
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should encode FalseClass data correctly' do
|
43
|
+
encoder = PgDataEncoder::EncodeForCopy.new
|
44
|
+
encoder.add [false]
|
45
|
+
encoder.close
|
46
|
+
io = encoder.get_io
|
47
|
+
existing_data = filedata("falseclass.dat")
|
48
|
+
str = io.read
|
49
|
+
io.class.name.should == "StringIO"
|
50
|
+
str.force_encoding("ASCII-8BIT")
|
51
|
+
str.should == existing_data
|
52
|
+
end
|
53
|
+
|
30
54
|
it 'should encode array data correctly' do
|
31
55
|
encoder = PgDataEncoder::EncodeForCopy.new
|
32
56
|
encoder.add [["hi", "jim"]]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_data_encoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/pg_data_encoder/encode_for_copy.rb
|
62
62
|
- lib/pg_data_encoder/version.rb
|
63
63
|
- pg_data_encoder.gemspec
|
64
|
+
- spec/errors_spec.rb
|
64
65
|
- spec/fixtures/3_col_array.txt
|
65
66
|
- spec/fixtures/3_col_hstore.dat
|
66
67
|
- spec/fixtures/3_col_hstore.txt
|
@@ -69,12 +70,14 @@ files:
|
|
69
70
|
- spec/fixtures/array_with_two2.dat
|
70
71
|
- spec/fixtures/big_str_array.dat
|
71
72
|
- spec/fixtures/big_str_array2.dat
|
73
|
+
- spec/fixtures/falseclass.dat
|
72
74
|
- spec/fixtures/float.dat
|
73
75
|
- spec/fixtures/intarray.dat
|
74
76
|
- spec/fixtures/just_an_array.dat
|
75
77
|
- spec/fixtures/just_an_array2.dat
|
76
78
|
- spec/fixtures/output.dat
|
77
79
|
- spec/fixtures/timestamp.dat
|
80
|
+
- spec/fixtures/trueclass.dat
|
78
81
|
- spec/spec_helper.rb
|
79
82
|
- spec/verify_data_formats_spec.rb
|
80
83
|
homepage: https://github.com/pbrumm/pg_data_encoder
|
@@ -103,6 +106,7 @@ specification_version: 3
|
|
103
106
|
summary: for faster input of data into postgres you can use this to generate the binary
|
104
107
|
import and run COPY FROM
|
105
108
|
test_files:
|
109
|
+
- spec/errors_spec.rb
|
106
110
|
- spec/fixtures/3_col_array.txt
|
107
111
|
- spec/fixtures/3_col_hstore.dat
|
108
112
|
- spec/fixtures/3_col_hstore.txt
|
@@ -111,11 +115,13 @@ test_files:
|
|
111
115
|
- spec/fixtures/array_with_two2.dat
|
112
116
|
- spec/fixtures/big_str_array.dat
|
113
117
|
- spec/fixtures/big_str_array2.dat
|
118
|
+
- spec/fixtures/falseclass.dat
|
114
119
|
- spec/fixtures/float.dat
|
115
120
|
- spec/fixtures/intarray.dat
|
116
121
|
- spec/fixtures/just_an_array.dat
|
117
122
|
- spec/fixtures/just_an_array2.dat
|
118
123
|
- spec/fixtures/output.dat
|
119
124
|
- spec/fixtures/timestamp.dat
|
125
|
+
- spec/fixtures/trueclass.dat
|
120
126
|
- spec/spec_helper.rb
|
121
127
|
- spec/verify_data_formats_spec.rb
|