Module: Dbviewer::DataExport

Extended by:
ActiveSupport::Concern
Included in:
DatabaseOperations
Defined in:
app/controllers/concerns/dbviewer/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



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

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_data = CSV.generate do |csv|
    # Add headers if requested
    csv << records.columns if include_headers

    # Add rows
    records.rows.each do |row|
      csv << row.map { |cell| format_csv_value(cell) }
    end
  end

  csv_data
end