Skip to content

Instantly share code, notes, and snippets.

@adamwiggins
Created March 14, 2009 01:51
Show Gist options
  • Save adamwiggins/78878 to your computer and use it in GitHub Desktop.
Save adamwiggins/78878 to your computer and use it in GitHub Desktop.
task :export do
require 'sequel'
require 'fastercsv'
db = Sequel.connect(ENV['DATABASE_URL'])
table_name = ENV['table'].to_sym
table = db[table_name]
fields = table.first.keys
csv = FasterCSV.generate do |csv|
csv << fields
table.all.each do |record|
csv << fields.map { |f| record[f] }
end
end
puts csv
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment