Skip to content

Development Status

Alex Petenchea edited this page Oct 6, 2024 · 7 revisions

Requirements

Long-term goals

  1. Support basic CRUD operations

Support basic CRUD operations

  1. Documentation
  • Use google-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. ✅
    • Add JWT authentication support ✅
  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)

Needed for first release

  1. CRUD Operations (single and multi-document)
  2. Transactions
  3. AQL support
  4. Basic management (list, truncate, create users)
  5. Support for x-arango-async
  6. Full test coverage
  7. All the above must be well documented with examples
Clone this wiki locally