-
Notifications
You must be signed in to change notification settings - Fork 2
Development Status
Alex Petenchea edited this page Oct 6, 2024
·
7 revisions
- Some degree of compatibility with python-arango
- Support generic types (see https://github.com/arangodb/python-arango/issues/304)
- Support basic CRUD operations
- Documentation
- Use google-style docstrings (using sphinx.ext.napoleon) ✅
- 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 ✅
- Arango Client
- Using the default HTTP client, create a basic ArangoClient ✅
- 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)
- CRUD Operations (single and multi-document)
- Transactions
- AQL support
- Basic management (list, truncate, create users)
- Support for
x-arango-async
- Full test coverage
- All the above must be well documented with examples