Creating Adapters¶
This guide outlines the minimum structure for a SQLSpec adapter and links to the example adapter skeleton.
Example¶
adapter skeleton¶from sqlspec.driver import SyncDriverAdapterBase
from sqlspec.exceptions import SQLSpecError
class ExampleDriver(SyncDriverAdapterBase):
def begin(self) -> None:
raise NotImplementedError
def commit(self) -> None:
raise NotImplementedError
def rollback(self) -> None:
raise NotImplementedError
def with_cursor(self, connection: Any) -> NoReturn:
raise NotImplementedError
def handle_database_exceptions(self) -> NoReturn:
msg = "Replace with adapter-specific handler"
raise SQLSpecError(msg)
def _connection_in_transaction(self) -> bool:
return False
Adapter Checklist¶
config.pywith a typed config class.driver.pyimplementing sync or async driver APIs.Optional
type_converter.pyand_types.pyfor DB-specific types.__init__.pyexports the public surface.