neo4j-contrib/neomodel

A (better?) interface to skip/limit

Demaga opened this issue · 2 comments

Demaga commented

Feature description (Mandatory)

I need a simple way to get LIMIT nodes of a specific class starting from SKIP.

Considered alternatives

I understand that I can set skip and limit attributes of NodeSet and then call .all method like this:

all_nodes = Person.nodes
all_nodes.skip = 5
all_nodes.limit = 5
all_nodes.all()
# [<Person: {'id': 6}>, <Person: {'id': 7}>, <Person: {'id': 8}>, <Person: {'id': 9}>, <Person: {'id': 10}>]

But IMO it's very unintuitive, especially because other methods do not require setting limits manually (.first, .get). Also I don't think this solution is mentioned in docs.

How this feature can improve the project?

I think for people working with large graphs it is important to have a clear nice interface to skip/limit. I solved it by implementing .get_many method for NodeSet.

all_nodes = Person.nodes.get_many(limit=5, skip=5)
all_nodes
# [<Person: {'id': 6}>, <Person: {'id': 7}>, <Person: {'id': 8}>, <Person: {'id': 9}>, <Person: {'id': 10}>]

Please let me know if I'm missing something and there is already a better way to use skip/limit for nodeset

Demaga commented

Omg I can't believe I missed it)
Thank you!