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
-
keys does 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 example a1, a2 = rel.fetch['attr1','attr2'] is equivalent to a1, a2 = rel.fetch('attr1','attr2'). However, __call__ can be modified such as a1, a2 = rel.fetch('attr1','attr2', order_by='attr1').
-
__iter__ stays, but cannot be modified. In addition, we provide the iterator traverse which accepts the same modifying keyword arguments as __call__. Additionally, traverse can get unnamed arguments. For example for a1, a2 in rel.fetch.traverse('attr1','attr2', limit=10):.
Currently, the fetch object is not elegant and potentially confusing to users. I propose the following changes to simplify it.
Stateless fetch
fetchbecomes completely stateless. This will simplify the implementation and make the process more transparent. All states become keyword arguments infetch. For examplerel.fetch.order_by('attribute').as_dict()becomesrel.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 thiskeysdoes 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):.