lib/mysql2xxxx/writer/csv.rb in mysql2xxxx-0.1.1 vs lib/mysql2xxxx/writer/csv.rb in mysql2xxxx-0.2.0
- old
+ new
@@ -4,13 +4,25 @@
require 'fastercsv'
end
module Mysql2xxxx
class CSV < Writer
+ SLASH_N = '\N'.freeze
def to_file(f)
- f.write keys.to_csv
+ slash_n = config.slash_n
+
+ if slash_n
+ f.write keys.map { |v| v.nil? ? SLASH_N : v }.to_csv
+ else
+ f.write keys.to_csv
+ end
+
stream_arrays do |ary|
- f.write ary.to_csv
+ if slash_n
+ f.write ary.map { |v| v.nil? ? SLASH_N : v }.to_csv
+ else
+ f.write ary.to_csv
+ end
end
nil
end
end
end