Class: QueryGuard::Explain::AdapterInterface
- Inherits:
-
Object
- Object
- QueryGuard::Explain::AdapterInterface
- Defined in:
- lib/query_guard/explain/adapter_interface.rb
Overview
Base interface for database-specific EXPLAIN plan adapters. Implementations should handle:
- Safe query execution without side effects
- Plan data extraction in JSON format
- Graceful error handling
Example:
adapter = PostgreSQLAdapter.new(connection)
plan = adapter.get_plan("SELECT * FROM users")
# => { "Plan" => { "Node Type" => "Seq Scan", ... }, ... }
Direct Known Subclasses
Instance Method Summary collapse
-
#can_explain?(sql) ⇒ Boolean
Check if adapter can execute EXPLAIN for this query type.
-
#engine_name ⇒ Symbol
Get engine name for this adapter.
-
#get_plan(sql, options = {}) ⇒ Hash
Get EXPLAIN plan for a query (JSON format when possible).
-
#initialize(connection) ⇒ AdapterInterface
constructor
Initialize adapter with database connection.
Constructor Details
#initialize(connection) ⇒ AdapterInterface
Initialize adapter with database connection
19 20 21 |
# File 'lib/query_guard/explain/adapter_interface.rb', line 19 def initialize(connection) @connection = connection end |
Instance Method Details
#can_explain?(sql) ⇒ Boolean
Check if adapter can execute EXPLAIN for this query type
50 51 52 |
# File 'lib/query_guard/explain/adapter_interface.rb', line 50 def can_explain?(sql) raise NotImplementedError, "Subclasses must implement can_explain?" end |
#engine_name ⇒ Symbol
Get engine name for this adapter
57 58 59 |
# File 'lib/query_guard/explain/adapter_interface.rb', line 57 def engine_name raise NotImplementedError, "Subclasses must implement engine_name" end |
#get_plan(sql, options = {}) ⇒ Hash
Get EXPLAIN plan for a query (JSON format when possible)
Example return structure (PostgreSQL):
{
"Plan" => {
"Node Type" => "Seq Scan",
"Relation Name" => "users",
"Plans" => [...],
"Actual Rows" => 100,
"Actual Total Time" => 2.543
},
"Planning Time" => 0.234,
"Execution Time" => 2.543
}
42 43 44 |
# File 'lib/query_guard/explain/adapter_interface.rb', line 42 def get_plan(sql, = {}) raise NotImplementedError, "Subclasses must implement get_plan" end |