Repository: SuperDuperDB/superduperdb
File: superduper/backends/base/data_backend.py (Python)

Code before:
from superduper.base import exceptions
from superduper.base.constant import KEY_BLOBS, KEY_BUILDS, KEY_FILES
from superduper.base.datatype import JSON, BaseDataType, NativeVector, Vector
from superduper.base.document import Document
from superduper.base.query import Query

if t.TYPE_CHECKING:
    from superduper.base.datalayer import Datalayer
    from superduper.base.event import CreateTable
    from superduper.base.schema import Schema


class BaseDataBackend(ABC):
    """Base data backend for the database.

    :param uri: URI to the databackend database.
    :param plugin: Plugin implementing the databackend.
    :param flavour: Flavour of the databackend.
    """

    tables_ignore: str | None = None
    json_native: bool = False

    batched: bool = False
    id_field: str = 'id'
    vector_impl: t.Type = NativeVector

    # TODO plugin not required
    # TODO flavour required?
    def __init__(self, uri: str, plugin: t.Any, flavour: t.Optional[str] = None):
        self.conn = None
        self.flavour = flavour
        self.in_memory: bool = False
        self.in_memory_tables: t.Dict = {}
        self.plugin = plugin
        self._db = None
        self.uri = uri
        self.bytes_encoding = 'bytes'

    @property
    def database(self):
        raise NotImplementedError

    @property
    def backend_name(self):
        return self.__class__.__name__.split('DataBackend')[0].lower()

    @property
    def type(self):
        """Return databackend."""
        raise NotImplementedError

Review comment (performance):
How about using a set of datatype implementations like this? That way, we can optimize the logic and make it easier to extend.

```python
datatypes_impl = {"vector": NativeVector, "json": "JsonXXX"}
```

Code after:
from superduper.base import exceptions
from superduper.base.constant import KEY_BLOBS, KEY_BUILDS, KEY_FILES, KEY_PATH
from superduper.base.datatype import JSON, BaseDataType, NativeVector, Vector
from superduper.base.document import Document
from superduper.base.query import Query

if t.TYPE_CHECKING:
    from superduper.base.datalayer import Datalayer
    from superduper.base.event import CreateTable
    from superduper.base.schema import Schema


class BaseDataBackend(ABC):
    """Base data backend for the database.

    :param uri: URI to the databackend database.
    :param plugin: Plugin implementing the databackend.
    :param flavour: Flavour of the databackend.
    """

    tables_ignore: str | None = None
    json_native: bool = False

    batched: bool = False
    id_field: str = 'id'
    vector_impl: t.Type = NativeVector

    # TODO plugin not required
    # TODO flavour required?
    def __init__(self, uri: str, plugin: t.Any, flavour: t.Optional[str] = None):
        self.conn = None
        self.flavour = flavour
        self.in_memory: bool = False
        self.in_memory_tables: t.Dict = {}
        self.plugin = plugin
        self._db = None
        self.uri = uri
        self.bytes_encoding = 'bytes'

    @property
    def database(self):
        raise NotImplementedError

    @property
    def backend_name(self):
        return self.__class__.__name__.split('DataBackend')[0].lower()

    @property
    def type(self):
        """Return databackend."""
        raise NotImplementedError