def query_results
ActiveRecord::Base.connection.execute('SELECT name FROM accounts;').to_a
end
# @params [Array<Hash>] records
def generate_csv(records)
attributes = records.first.keys
CSV.generate(headers: true) do |csv|
csv << attributes
records.each do |record|
csv << record
end
end
end
# requires aws-sdk
def prepare_s3
Aws.config.update(
{
region: 'us-west-2',
credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']),
}
)
end
def export(data, bucket_name, file_name)
object = Aws::S3::Resource.new.bucket(bucket_name).object(file_name)
object.put(body: data)
end