Class: Mysqlexport::Csv

Inherits:
Writer
  • Object
show all
Defined in:
lib/mysqlexport/writer/csv.rb

Instance Attribute Summary

Attributes inherited from Writer

#client, #config, #sql

Instance Method Summary collapse

Methods inherited from Writer

#filter_path, #to_path, #to_s, #to_stdout

Constructor Details

#initialize(options = {}) ⇒ Csv

Returns a new instance of Csv.



8
9
10
# File 'lib/mysqlexport/writer/csv.rb', line 8

def initialize(options = {})
  super(**options)
end

Instance Method Details

#to_file(file) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/mysqlexport/writer/csv.rb', line 12

def to_file(file)
  result = client.query(config.execute, stream: true, cache_rows: false, as: :array)
  csv_o = csv_options
  file.write result.fields.to_csv(**csv_o) if config.csv_heading
  result.each do |row|
    file.write row.to_csv(**csv_o)
  end
end