Last active
January 29, 2016 12:16
-
-
Save lappi-lynx/1c408e5fd28f4462dd55 to your computer and use it in GitHub Desktop.
Allows you to convert data from SQL into CSV format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First connect to DB with needed sql data | |
class T < ActiveRecord::Base | |
establish_connection({adapter:'mysql2', database:'db_for_test', encoding:'utf8',user:'', password: ''}) | |
set_table_name 'utility_company' | |
end | |
CSV.open("data.csv", "wb") do |csv| | |
csv << T.first.attribute_names # adds the attributes name on the first line | |
T.all.each do |hash| | |
csv << hash.attributes.values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment