Skip to content

Simplify fetch #318

@fabiansinz

Description

@fabiansinz

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):.

Metadata

Metadata

Assignees

Labels

enhancementIndicates new improvements

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions