DAT-1076: Add Capability enum and supports() method to replace getSupportFor* methods#794
DAT-1076: Add Capability enum and supports() method to replace getSupportFor* methods#794
Conversation
…portFor* methods
- Create Capability enum with all existing capability types (54 capabilities)
- Create NotSupported exception class for cleaner error handling
- Add abstract supports() method to Adapter base class
- Add requireSupport() helper method that throws NotSupported when capability is missing
- Add getAdapterName() abstract method for error messages
- Implement supports() method in SQL, MariaDB, MySQL, SQLite, Postgres, Mongo, and Pool adapters
- Add supports() wrapper method to Database class
This provides a unified API for checking adapter capabilities:
if (!$this->supports(Capability::FullTextIndex)) {
throw new NotSupported(Capability::FullTextIndex->value, $this->getAdapterName());
}
Or using the helper method:
$this->requireSupport(Capability::FullTextIndex);
The existing getSupportFor* methods are preserved for backward compatibility.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughA new capability-based feature support system is introduced across database adapters. A string-backed Capability enum centralizes feature definitions (schemas, indexes, vectors, etc.). Base Adapter adds abstract methods for adapter naming and capability checks, plus a concrete requireSupport() method. Concrete adapters implement getAdapterName(); MongoDB and SQL implement comprehensive supports() logic via match expressions. Pool and Database classes delegate to underlying adapters. A new NotSupported exception reports unsupported capabilities with adapter context. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Database
participant Adapter
participant Capability as Capability<br/>(Enum)
Client->>Database: supports(Capability.Vectors)
activate Database
Database->>Adapter: supports(Capability.Vectors)
activate Adapter
Adapter->>Capability: match against case
Adapter->>Adapter: evaluate capability support
alt Capability supported
Adapter-->>Database: true
else Capability not supported
Adapter-->>Database: false
end
deactivate Adapter
Database-->>Client: boolean result
deactivate Database
Note over Adapter: requireSupport() variant<br/>throws NotSupported if false
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Capabilityenum with all existing capability types (54 capabilities)NotSupportedexception class for cleaner error handlingsupports(Capability $capability): boolmethod to Adapter base classrequireSupport(Capability $capability)helper method that throwsNotSupportedwhen capability is missinggetAdapterName()abstract method for error messages in exceptionssupports()method in SQL, MariaDB, MySQL, SQLite, Postgres, Mongo, and Pool adapterssupports()wrapper method to Database classUsage
This provides a unified API for checking adapter capabilities:
Or using the helper method:
Backward Compatibility
The existing
getSupportFor*methods are preserved for backward compatibility. The newsupports()method delegates to these methods internally.Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
✏️ Tip: You can customize this high-level summary in your review settings.