Class: Dbviewer::Api::EntityRelationshipDiagramsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- Dbviewer::ApplicationController
- BaseController
- Dbviewer::Api::EntityRelationshipDiagramsController
- Defined in:
- app/controllers/dbviewer/api/entity_relationship_diagrams_controller.rb
Instance Method Summary collapse
Methods inherited from BaseController
#render_error, #render_success
Methods included from ErrorHandling
#handle_database_error, #log_error
Methods included from DatabaseOperations
#current_table?, #database_manager, #execute_query, #export_table_to_csv, #fetch_database_analytics, #fetch_filtered_record_count, #fetch_mini_erd_for_table, #fetch_table_columns, #fetch_table_metadata, #fetch_table_record_count, #fetch_table_records, #fetch_table_relationships, #fetch_tables, #get_adapter_name, #get_database_name, #prepare_query, #safe_quote_table_name, #table_query_operations
Instance Method Details
#relationships ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/dbviewer/api/entity_relationship_diagrams_controller.rb', line 6 def relationships # Fetch all relationships asynchronously begin @table_relationships = fetch_table_relationships render_success({ relationships: @table_relationships, status: "success" }) rescue => e Rails.logger.error("[DBViewer] Error fetching relationships: #{e.}") render json: { relationships: [], status: "error", error: e. }, status: :internal_server_error end end |
#table_relationships ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/dbviewer/api/entity_relationship_diagrams_controller.rb', line 24 def table_relationships # Fetch relationships for specific tables table_names = params[:tables]&.split(",") || [] if table_names.blank? render json: { relationships: [], status: "error", error: "No tables specified" }, status: :bad_request return end begin relationships = [] table_names.each do |table_name| next unless @tables.any? { |t| t[:name] == table_name } begin = (table_name) if && [:foreign_keys].present? [:foreign_keys].each do |fk| relationships << { from_table: table_name, to_table: fk[:to_table], from_column: fk[:column], to_column: fk[:primary_key], name: fk[:name] } end end rescue => e Rails.logger.error("[DBViewer] Error fetching relationships for #{table_name}: #{e.}") # Continue with other tables even if one fails end end render_success({ relationships: relationships, status: "success", processed_tables: table_names }) rescue => e Rails.logger.error("[DBViewer] Error in table_relationships: #{e.}") render json: { relationships: [], status: "error", error: e. }, status: :internal_server_error end end |