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.py with a typed config class.

  • driver.py implementing sync or async driver APIs.

  • Optional type_converter.py and _types.py for DB-specific types.

  • __init__.py exports the public surface.

See Also

  • Driver for required driver methods.

  • Adapters for config naming conventions.