Class: SqlQueryAnalyzer::QueryPlanPresenter
- Inherits:
-
Object
- Object
- SqlQueryAnalyzer::QueryPlanPresenter
- Defined in:
- lib/sql_query_analyzer/query_plan_presenter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #display ⇒ Object
-
#initialize(output:, warnings:, total_cost:, rows_estimate:, actual_time:) ⇒ QueryPlanPresenter
constructor
A new instance of QueryPlanPresenter.
Constructor Details
#initialize(output:, warnings:, total_cost:, rows_estimate:, actual_time:) ⇒ QueryPlanPresenter
Returns a new instance of QueryPlanPresenter.
5 6 7 8 9 10 11 12 |
# File 'lib/sql_query_analyzer/query_plan_presenter.rb', line 5 def initialize(output:, warnings:, total_cost:, rows_estimate:, actual_time:) @output = output @warnings = warnings @total_cost = total_cost @rows_estimate = rows_estimate @actual_time = actual_time @pastel = Pastel.new end |
Class Method Details
.classify_cost(cost) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sql_query_analyzer/query_plan_presenter.rb', line 36 def self.classify_cost(cost) return unless cost pastel = Pastel.new case cost when 0..300 puts pastel.green("\n✅ Query cost is LOW. All good!") when 301..1000 puts pastel.yellow("\n🧐 Query cost is MODERATE. May benefit from optimizations.") else puts pastel.red.bold("\n🛑 Query cost is HIGH. Recommend tuning immediately!") end end |
Instance Method Details
#display ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sql_query_analyzer/query_plan_presenter.rb', line 14 def display puts @pastel.bold("\n🔍 QUERY PLAN:") @output.each_with_index do |line, idx| puts " #{@pastel.cyan("#{idx + 1}:")} #{line}" end puts @pastel.bold("\n📊 Query Metrics:") puts " 💰 Total Cost: #{@pastel.green(@total_cost)}" if @total_cost puts " 📈 Rows Estimate: #{@pastel.blue(@rows_estimate)}" if @rows_estimate puts " ⏱️ Actual Time: #{@pastel.magenta("#{@actual_time} ms")}" if @actual_time if @warnings.any? puts @pastel.bold("\n🚩 Warnings and Suggestions:") @warnings.each do |warn| puts " #{@pastel.yellow("Line #{warn[:line_number]}:")} #{warn[:line_text]}" puts " 👉 #{colorize_by_severity(warn[:suggestion])}" end else puts @pastel.green("\n✅ No immediate problems detected in the query plan.") end end |