pg_data_encoder 0.0.9 → 0.1.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.
data/README.md CHANGED
@@ -72,8 +72,8 @@ or
72
72
  * Floats (double precision)
73
73
  * Timestamp
74
74
  * Date
75
- * Array (integer and string single dimension)
76
- * UUID (through passing column_map: {0 => :uuid} to options hash)
75
+ * Array (integer, string, uuid single dimension) (uuid needs to specify column_types of :uuid)
76
+ * UUID (through passing column_types: {0 => :uuid} to options hash)
77
77
 
78
78
  ## Contributing
79
79
 
@@ -7,6 +7,7 @@ module PgDataEncoder
7
7
  def initialize(options = {})
8
8
  @options = options
9
9
  @closed = false
10
+ options[:column_types] ||= {}
10
11
  @io = nil
11
12
  end
12
13
 
@@ -90,19 +91,35 @@ module PgDataEncoder
90
91
  completed = false
91
92
  case field[0]
92
93
  when String
93
- array_io.write([1].pack("N")) # unknown
94
- array_io.write([0].pack("N")) # unknown
94
+ if @options[:column_types][index] == :uuid
95
+ array_io.write([1].pack("N")) # unknown
96
+ array_io.write([0].pack("N")) # unknown
95
97
 
96
- array_io.write([1043].pack("N")) # I think is used to determine string data type
97
- array_io.write([field.size].pack("N"))
98
- array_io.write([1].pack("N")) # forcing single dimension array for now
99
-
100
- field.each_with_index {|val, index|
101
- buf = val.to_s.encode("UTF-8")
102
- array_io.write([buf.bytesize].pack("N"))
103
- array_io.write(buf)
98
+ array_io.write([2950].pack("N")) # I think is used to determine string data type
99
+ array_io.write([field.size].pack("N"))
100
+ array_io.write([1].pack("N")) # forcing single dimension array for now
104
101
 
105
- }
102
+ field.each_with_index {|val, index|
103
+ array_io.write([16].pack("N"))
104
+ c = [val.gsub(/-/, "")].pack('H*')
105
+ array_io.write(c)
106
+
107
+ }
108
+ else
109
+ array_io.write([1].pack("N")) # unknown
110
+ array_io.write([0].pack("N")) # unknown
111
+
112
+ array_io.write([1043].pack("N")) # I think is used to determine string data type
113
+ array_io.write([field.size].pack("N"))
114
+ array_io.write([1].pack("N")) # forcing single dimension array for now
115
+
116
+ field.each_with_index {|val, index|
117
+ buf = val.to_s.encode("UTF-8")
118
+ array_io.write([buf.bytesize].pack("N"))
119
+ array_io.write(buf)
120
+
121
+ }
122
+ end
106
123
  when Integer
107
124
  array_io.write([1].pack("N")) # unknown
108
125
  array_io.write([0].pack("N")) # unknown
@@ -1,3 +1,3 @@
1
1
  module PgDataEncoder
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
Binary file
@@ -224,4 +224,18 @@ describe "generating data" do
224
224
  str.should == existing_data
225
225
  end
226
226
 
227
+
228
+ it 'should encode uuid correctly from tempfile' do
229
+ encoder = PgDataEncoder::EncodeForCopy.new(:use_tempfile => true, column_types: {0 => :uuid})
230
+ encoder.add [['6272bd7d-adae-44b7-bba1-dca871c2a6fd', '7dc8431f-fcce-4d4d-86f3-6857cba47d38']]
231
+ encoder.close
232
+ io = encoder.get_io
233
+ existing_data = filedata("uuid_array.dat")
234
+ str = io.read
235
+ io.class.name.should == "Tempfile"
236
+ str.force_encoding("ASCII-8BIT")
237
+ #File.open("spec/fixtures/output.dat", "w:ASCII-8BIT") {|out| out.write(str) }
238
+ str.should == existing_data
239
+ end
240
+
227
241
  end
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.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -82,6 +82,7 @@ files:
82
82
  - spec/fixtures/timestamp.dat
83
83
  - spec/fixtures/trueclass.dat
84
84
  - spec/fixtures/uuid.dat
85
+ - spec/fixtures/uuid_array.dat
85
86
  - spec/spec_helper.rb
86
87
  - spec/verify_data_formats_spec.rb
87
88
  homepage: https://github.com/pbrumm/pg_data_encoder
@@ -131,6 +132,7 @@ test_files:
131
132
  - spec/fixtures/timestamp.dat
132
133
  - spec/fixtures/trueclass.dat
133
134
  - spec/fixtures/uuid.dat
135
+ - spec/fixtures/uuid_array.dat
134
136
  - spec/spec_helper.rb
135
137
  - spec/verify_data_formats_spec.rb
136
138
  has_rdoc: