Class: RailsConsolePro::ExplainResult
- Inherits:
-
Object
- Object
- RailsConsolePro::ExplainResult
- Defined in:
- lib/rails_console_pro/explain_result.rb
Overview
Value object for SQL explain results
Instance Attribute Summary collapse
-
#execution_time ⇒ Object
readonly
Returns the value of attribute execution_time.
-
#explain_output ⇒ Object
readonly
Returns the value of attribute explain_output.
-
#indexes_used ⇒ Object
readonly
Returns the value of attribute indexes_used.
-
#recommendations ⇒ Object
readonly
Returns the value of attribute recommendations.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
Instance Method Summary collapse
-
#export_to_file(file_path, format: nil) ⇒ Object
Export to file.
- #has_indexes? ⇒ Boolean
-
#initialize(sql:, explain_output:, execution_time: nil, indexes_used: [], recommendations: [], statistics: nil) ⇒ ExplainResult
constructor
A new instance of ExplainResult.
- #slow_query? ⇒ Boolean
-
#to_html(style: :default) ⇒ Object
Export to HTML.
-
#to_json(pretty: true) ⇒ Object
Export to JSON.
-
#to_yaml ⇒ Object
Export to YAML.
Constructor Details
#initialize(sql:, explain_output:, execution_time: nil, indexes_used: [], recommendations: [], statistics: nil) ⇒ ExplainResult
9 10 11 12 13 14 15 16 17 |
# File 'lib/rails_console_pro/explain_result.rb', line 9 def initialize(sql:, explain_output:, execution_time: nil, indexes_used: [], recommendations: [], statistics: nil) @sql = sql @explain_output = explain_output @execution_time = execution_time @indexes_used = Array(indexes_used) @recommendations = Array(recommendations) @statistics = statistics || {} end |
Instance Attribute Details
#execution_time ⇒ Object (readonly)
Returns the value of attribute execution_time.
6 7 8 |
# File 'lib/rails_console_pro/explain_result.rb', line 6 def execution_time @execution_time end |
#explain_output ⇒ Object (readonly)
Returns the value of attribute explain_output.
6 7 8 |
# File 'lib/rails_console_pro/explain_result.rb', line 6 def explain_output @explain_output end |
#indexes_used ⇒ Object (readonly)
Returns the value of attribute indexes_used.
6 7 8 |
# File 'lib/rails_console_pro/explain_result.rb', line 6 def indexes_used @indexes_used end |
#recommendations ⇒ Object (readonly)
Returns the value of attribute recommendations.
6 7 8 |
# File 'lib/rails_console_pro/explain_result.rb', line 6 def recommendations @recommendations end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
6 7 8 |
# File 'lib/rails_console_pro/explain_result.rb', line 6 def sql @sql end |
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
6 7 8 |
# File 'lib/rails_console_pro/explain_result.rb', line 6 def statistics @statistics end |
Instance Method Details
#export_to_file(file_path, format: nil) ⇒ Object
Export to file
43 44 45 |
# File 'lib/rails_console_pro/explain_result.rb', line 43 def export_to_file(file_path, format: nil) FormatExporter.export_to_file(self, file_path, format: format) end |
#has_indexes? ⇒ Boolean
23 24 25 |
# File 'lib/rails_console_pro/explain_result.rb', line 23 def has_indexes? indexes_used.any? end |
#slow_query? ⇒ Boolean
19 20 21 |
# File 'lib/rails_console_pro/explain_result.rb', line 19 def slow_query? execution_time && execution_time > 100 end |
#to_html(style: :default) ⇒ Object
Export to HTML
38 39 40 |
# File 'lib/rails_console_pro/explain_result.rb', line 38 def to_html(style: :default) FormatExporter.to_html(self, title: "SQL Explain Analysis", style: style) end |
#to_json(pretty: true) ⇒ Object
Export to JSON
28 29 30 |
# File 'lib/rails_console_pro/explain_result.rb', line 28 def to_json(pretty: true) FormatExporter.to_json(self, pretty: pretty) end |
#to_yaml ⇒ Object
Export to YAML
33 34 35 |
# File 'lib/rails_console_pro/explain_result.rb', line 33 def to_yaml FormatExporter.to_yaml(self) end |