Class: QueryGuard::Migrations::DatabaseAdapter
- Inherits:
-
Object
- Object
- QueryGuard::Migrations::DatabaseAdapter
- Defined in:
- lib/query_guard/migrations/database_adapter.rb
Overview
Abstract interface for database metadata adapters.
Adapters implement this interface to provide table metadata (row counts, lock behavior, etc.) from different database systems.
Example:
adapter = PostgreSQLAdapter.new(connection)
rows = adapter.estimate_table_rows(:users)
Adapters should:
- Handle connection failures gracefully
- Return nil or empty hash if data unavailable
- Cache results where possible
- Never raise exceptions during metadata queries
Direct Known Subclasses
Instance Method Summary collapse
-
#connected? ⇒ Boolean
Check if connection is healthy.
-
#estimate_lock_risk(table_name) ⇒ Symbol?
Get lock impact estimate for a table.
-
#estimate_table_rows(table_name) ⇒ Integer?
Get estimated row count for a table.
-
#list_tables ⇒ Array<String>
Get all table names in current schema.
-
#table_exists?(table_name) ⇒ Boolean
Check if table exists in database.
Instance Method Details
#connected? ⇒ Boolean
Check if connection is healthy
57 58 59 |
# File 'lib/query_guard/migrations/database_adapter.rb', line 57 def connected? raise NotImplementedError, "Subclasses must implement connected?" end |
#estimate_lock_risk(table_name) ⇒ Symbol?
Get lock impact estimate for a table
Scores table's lock risk based on size and activity. Based on PostgreSQL's vacuum and maintenance overhead.
35 36 37 |
# File 'lib/query_guard/migrations/database_adapter.rb', line 35 def estimate_lock_risk(table_name) raise NotImplementedError, "Subclasses must implement estimate_lock_risk" end |
#estimate_table_rows(table_name) ⇒ Integer?
Get estimated row count for a table
24 25 26 |
# File 'lib/query_guard/migrations/database_adapter.rb', line 24 def estimate_table_rows(table_name) raise NotImplementedError, "Subclasses must implement estimate_table_rows" end |
#list_tables ⇒ Array<String>
Get all table names in current schema
50 51 52 |
# File 'lib/query_guard/migrations/database_adapter.rb', line 50 def list_tables raise NotImplementedError, "Subclasses must implement list_tables" end |
#table_exists?(table_name) ⇒ Boolean
Check if table exists in database
43 44 45 |
# File 'lib/query_guard/migrations/database_adapter.rb', line 43 def table_exists?(table_name) raise NotImplementedError, "Subclasses must implement table_exists?" end |