Skip to content

Development Status

Alex Petenchea edited this page Jul 21, 2024 · 7 revisions

Requirements

Long-term goals

  1. Support basic CRUD operations

Support basic CRUD operations

  1. Documentation
  • Use numpy-style docstrings (using sphinx.ext.napoleon)
  1. HTTP Client
    • Introduce AioHTTPClient 🚧
    • Simplify request and response as much as possible. Request and Response classes should not be responsible with serialization. They are low-level classes. Introducing generic types at that level makes customization hard, and this is something the community wishes to have.
  2. Arango Client
    • Using the default HTTP client, create a basic ArangoClient
  3. Serialization
  • For serialization and de-serialization, we should a strategy pattern and let clients customize the process through that. Would be cool to also allow them to customize the default serializer for a given type.
import json

class BaseSerializer:
    def __init__(self):
        self._serializers = {}

    def register_serializer(self, type_: TypeVar, serializer: Callable[[Any], str]):
        self._serializers[type_] = serializer

    def serialize(self, data: Any) -> str:
        serializer = self._serializers.get(type(data), json.dumps)
        return serializer(data)

    def deserialize(self, data: str, type_: TypeVar) -> Any:
        if type_ in self._serializers:
            return self._serializers[type_](data)
        return json.loads(data)

Using generic could look something like this:

Serializer = Callable[[T], str]
Deserializer = Callable[[str], T]

from typing import Optional

class ArangoDBClient(Generic[T]):
    def __init__(self,
                 serializer: Optional[Serializer[T]] = None,
                 deserializer: Optional[Deserializer[T]] = None):
        self.serializer = serializer or (lambda x: json.dumps(x))  # Default serializer
        self.deserializer = deserializer or (lambda x: json.loads(x))  # Default deserializer

    def insert_document(self, collection: str, document: T):
        serialized_data = self.serializer(document)
        # Here you would have code to insert the serialized data into the database
        print(f"Inserting into {collection}: {serialized_data}")

    def get_document(self, collection: str, doc_id: str) -> T:
        # Here you would retrieve the data from the database
        serialized_data = '{"name": "example", "value": 123}'  # Example data
        return self.deserializer(serialized_data)
Clone this wiki locally