Class: QueryConsole::SchemaController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- QueryConsole::SchemaController
- Defined in:
- app/controllers/query_console/schema_controller.rb
Instance Method Summary collapse
-
#bulk ⇒ Object
Bulk endpoint to fetch all tables with columns in a single request Prevents N+1 problem for autocomplete.
- #show ⇒ Object
- #tables ⇒ Object
Instance Method Details
#bulk ⇒ Object
Bulk endpoint to fetch all tables with columns in a single request Prevents N+1 problem for autocomplete
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 |
# File 'app/controllers/query_console/schema_controller.rb', line 34 def bulk unless QueryConsole.configuration.autocomplete_enabled render json: { error: "Autocomplete is disabled" }, status: :forbidden return end config = QueryConsole.configuration introspector = SchemaIntrospector.new # Apply autocomplete limits max_tables = config.autocomplete_max_tables max_columns = config.autocomplete_max_columns_per_table tables = introspector.tables.first(max_tables) # Fetch all table details in one pass (server-side batching) tables_with_columns = tables.map do |table| details = introspector.table_details(table[:name]) columns = details ? details[:columns].first(max_columns).map { |c| c[:name] } : [] { name: table[:name], kind: table[:kind], columns: columns } end render json: tables_with_columns end |
#show ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/query_console/schema_controller.rb', line 15 def show unless QueryConsole.configuration.schema_explorer render json: { error: "Schema explorer is disabled" }, status: :forbidden return end introspector = SchemaIntrospector.new @table = introspector.table_details(params[:name]) if @table.nil? render json: { error: "Table not found or access denied" }, status: :not_found return end render json: @table end |
#tables ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/query_console/schema_controller.rb', line 3 def tables unless QueryConsole.configuration.schema_explorer render json: { error: "Schema explorer is disabled" }, status: :forbidden return end introspector = SchemaIntrospector.new @tables = introspector.tables render json: @tables end |