Class: Dbviewer::Api::TablesController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- Dbviewer::ApplicationController
- BaseController
- Dbviewer::Api::TablesController
- Defined in:
- app/controllers/dbviewer/api/tables_controller.rb
Instance Method Summary collapse
Methods inherited from BaseController
#render_error, #render_success
Methods included from DatabaseOperations
#database_manager, #table_query_operations
Methods included from DatatableSupport
Methods included from DataExport
Methods included from QueryOperations
#default_query, #execute_query, #prepare_query
Methods included from RelationshipManagement
#fetch_mini_erd_for_table, #fetch_table_relationships
Methods included from TableOperations
#fetch_filtered_record_count, #fetch_table_columns, #fetch_table_metadata, #fetch_table_record_count, #fetch_table_records, #fetch_tables, #safe_quote_table_name
Methods included from DatabaseInformation
#fetch_database_analytics, #get_adapter_name, #get_database_name
Methods included from ConnectionManagement
#available_connections, #current_connection_key, #switch_connection
Instance Method Details
#index ⇒ Object
4 5 6 7 |
# File 'app/controllers/dbviewer/api/tables_controller.rb', line 4 def index tables_count = fetch_tables_count render_success(total_tables: tables_count) end |
#records ⇒ Object
9 10 11 12 |
# File 'app/controllers/dbviewer/api/tables_controller.rb', line 9 def records tables_stats = fetch_tables_stats render_success(tables_stats) end |
#relationship_counts ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/dbviewer/api/tables_controller.rb', line 19 def relationship_counts table_name = params[:id] record_id = params[:record_id] reverse_foreign_keys = (table_name).dig(:reverse_foreign_keys) || [] relationship_counts = reverse_foreign_keys.map do |rel| { table: rel[:from_table], foreign_key: rel[:column], count: database_manager.get_model_for(rel[:from_table]).where(rel[:column] => record_id).count } end render_success({ table_name: table_name, record_id: record_id, relationships: relationship_counts }) end |
#relationships_count ⇒ Object
14 15 16 17 |
# File 'app/controllers/dbviewer/api/tables_controller.rb', line 14 def relationships_count total_relationships = calculate_total_relationships render_success(total_relationships: total_relationships) end |