Module: Dbviewer::DatabaseOperations::DataExport

Extended by:
ActiveSupport::Concern
Included in:
Dbviewer::DatabaseOperations
Defined in:
app/controllers/concerns/dbviewer/database_operations/data_export.rb

Instance Method Summary collapse

Instance Method Details

#export_table_to_csv(table_name, query_params = nil, include_headers = true) ⇒ Object

Export table data to CSV



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/concerns/dbviewer/database_operations/data_export.rb', line 9

def export_table_to_csv(table_name, query_params = nil, include_headers = true)
  records = database_manager.table_query_operations.table_records(table_name, query_params)

  CSV.generate do |csv|
    csv << records.columns if include_headers

    record_body = records.rows.map do |row|
      row.map { |cell| format_csv_value(cell) }
    end
    csv.concat(record_body)
  end
end