module DBA::CSV
Public Class Methods
dump(database, table_name, path)
click to toggle source
# File lib/dba/csv.rb, line 5 def self.dump(database, table_name, path) columns = nil ::CSV.open(path, 'wb') do |csv| database[table_name].each_with_index do |row, index| if index.zero? columns = row.keys csv << columns end csv << row.values_at(*columns) end end end
load(path, database, table_name)
click to toggle source
# File lib/dba/csv.rb, line 21 def self.load(path, database, table_name) dataset = database[table_name] rows = ::CSV.read(path) headers = rows.shift dataset.import(headers, rows) end