adamwiggins (owner)

Forks

Revisions

gist: 78878 Download_button fork
public
Public Clone URL: git://gist.github.com/78878.git
Embed All Files: show embed
export_via_sequel.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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