-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Currently, the fetch object is not elegant and potentially confusing to users. I propose the following changes to simplify it.
Stateless fetch
fetch becomes completely stateless. This will simplify the implementation and make the process more transparent. All states become keyword arguments in fetch. For example rel.fetch.order_by('attribute').as_dict() becomes rel.fetch(as_dict=True, order_by='attribute'). All previous states become forced keyword arguments.
getitem and iterators
Fetch keeps __getitem__, keys, and __iter__. The disadvantage that comes with the stateless implementation is that the ways the elements are fetched cannot easily be modified for most of these functions. The following changes would solve this
-
keysdoes accept arguments like__call__(i.e.rel.keys(order_by='attr1')) -
__call__does also accept unnamed arguments. In that case it behaves like__getitem__but with possible modifications. For examplea1, a2 = rel.fetch['attr1','attr2']is equivalent toa1, a2 = rel.fetch('attr1','attr2'). However,__call__can be modified such asa1, a2 = rel.fetch('attr1','attr2', order_by='attr1'). -
__iter__stays, but cannot be modified. In addition, we provide the iteratortraversewhich accepts the same modifying keyword arguments as__call__. Additionally,traversecan get unnamed arguments. For examplefor a1, a2 in rel.fetch.traverse('attr1','attr2', limit=10):.