When checking for database backend capabilities, always use feature flags rather than checking specific vendor names. This makes your code more maintainable and vendor-agnostic while allowing third-party backends to implement support through the feature flag system.
Instead of explicitly checking the vendor:
if connection.vendor == "sqlite":
# SQLite-specific implementation
...
else:
# Implementation for other databases
...
Declare and use feature flags:
# In database feature definition
class DatabaseFeatures:
supports_json_absent_on_null = property(lambda self: self.connection.vendor != "sqlite")
# In your code
if connection.features.supports_json_absent_on_null:
# Use feature requiring JSON ABSENT ON NULL
...
else:
# Use alternative implementation or raise NotSupportedError
raise NotSupportedError("This database does not support ABSENT ON NULL")
This pattern centralizes capability detection in feature flags rather than spreading vendor-specific checks throughout the codebase, making it easier to update support for features across different database backends.
Enter the URL of a public GitHub repository