Class: Dbviewer::TablesController
Instance Method Summary
collapse
#calculate_total_pages, #set_pagination_params, #set_sorting_params
#handle_database_error, #log_error
#calculate_schema_size, #current_table?, #database_manager, #execute_query, #export_table_to_csv, #fetch_database_analytics, #fetch_filtered_record_count, #fetch_table_columns, #fetch_table_metadata, #fetch_table_record_count, #fetch_table_records, #fetch_table_relationships, #fetch_tables_with_stats, #get_database_name, #prepare_query, #safe_quote_table_name
Instance Method Details
#export_csv ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/dbviewer/tables_controller.rb', line 64
def export_csv
table_name = params[:id]
limit = (params[:limit] || 10000).to_i
= params[:include_headers] != "0"
csv_data = export_table_to_csv(table_name, limit, )
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
filename = "#{table_name}_export_#{timestamp}.csv"
send_data csv_data,
type: "text/csv; charset=utf-8; header=present",
disposition: "attachment; filename=#{filename}"
end
|
#index ⇒ Object
5
6
7
|
# File 'app/controllers/dbviewer/tables_controller.rb', line 5
def index
@tables = fetch_tables_with_stats(include_record_counts: true)
end
|
#query ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/dbviewer/tables_controller.rb', line 49
def query
@table_name = params[:id]
@read_only_mode = true @columns = fetch_table_columns(@table_name)
@tables = fetch_tables_with_stats
@active_table = @table_name
prepare_query
execute_query
render :query
end
|
#show ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/dbviewer/tables_controller.rb', line 9
def show
@table_name = params[:id]
@columns = fetch_table_columns(@table_name)
@metadata = fetch_table_metadata(@table_name)
@tables = fetch_tables_with_stats
set_sorting_params
@column_filters = params[:column_filters].presence ? params[:column_filters].to_enum.to_h : {}
if @column_filters.present? && @column_filters.values.any?(&:present?)
@total_count = fetch_filtered_record_count(@table_name, @column_filters)
else
@total_count = fetch_table_record_count(@table_name)
end
@total_pages = calculate_total_pages(@total_count, @per_page)
@records = fetch_table_records(@table_name)
if has_timestamp_column?(@table_name)
@time_grouping = params[:time_group] || "daily"
@timestamp_data = fetch_timestamp_data(@table_name, @time_grouping)
end
respond_to do |format|
format.html format.json do
render json: {
table_name: @table_name,
columns: @columns,
metadata: @metadata,
record_count: @total_count
}
end
end
end
|