lib/mysql2xxxx/csv.rb in mysql2xxxx-0.0.2 vs lib/mysql2xxxx/csv.rb in mysql2xxxx-0.0.3

- old
+ new

@@ -12,22 +12,21 @@ def initialize(options = {}) @properties = Properties.new options end - def client - @client ||= Client.new properties - end - def to_file(f) + @client = ::Mysql2::Client.new properties.database_config keys = nil - client.select_each(properties.execute) do |hsh| + @client.query(properties.execute).each do |hsh| unless keys keys = hsh.keys f.write keys.to_csv end f.write keys.inject([]) { |memo, k| memo.push hsh[k] }.to_csv end nil + ensure + @client.try :close end end end