redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.12k stars 112 forks source link

Add a `page` function for `find` #284

Closed simonprickett closed 2 years ago

simonprickett commented 2 years ago

Allow the user to page through all results rather than returning them all in one go... .find().page(offset, limit). See Redis OM Node for a good example.

mpmX commented 2 years ago

In the meantime, FindQuery(expressions=[], model=self.model, offset=skip, limit=limit).execute() works for me

iamvishalkhare commented 2 years ago

In the meantime, FindQuery(expressions=[], model=self.model, offset=skip, limit=limit).execute() works for me

How do I use this? Can you put up an example code snippet?

mpmX commented 2 years ago

How do I use this? Can you put up an example code snippet?

Assuming your model class is called Entity:

from redis_om import FindQuery
expressions = [(Entity.some_attribute == 1)]
skip = 10
limit = 10
result = FindQuery(expressions=expressions, model=Entity, offset=skip, limit=limit).execute()
sav-norem commented 2 years ago

Current functionality of the execution of queries appends all results together - https://github.com/redis/redis-om-python/blob/dcd84e0ab2686a3c6ff7f6c6a43ec49f4b65655f/aredis_om/model/model.py#L740

This change will require changing how results are returned to users, not just adding a function. Closed the draft PR I had for this after realizing the above.

sav-norem commented 2 years ago

@simonprickett - wiseaidev implemented this how it's described so I think we should go ahead and close this