-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PanacheQuery.range() #3870
Comments
This issue/pullrequest has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still needed this functionality. |
@loicmathieu it's similar to JPA's @FroMage happy with the API |
@emmanuelbernard yes, and I'm not happy with my implementation, but currently PanacheQuery implementation always use pagination. I can think of two options:
Because, if we directly use the index, we will skip the pagination stuff and if the user use it after a range query it will be inconsistent. |
Well, |
Also, can I have some example use-cases of ranges? I've never seen APIs that use non-pageable ranges before, so I hope this is not one of those "hey it would be cool" features with no actual use-case ;) |
In my previous Job, we implement pagination for all our API (more than 30 APIs) using HTTP range: https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests So the user will include a I would say, range are as common as pagination but I'm not sure. |
@FroMage WDYT of this ? |
Well, how can we do ranges if the paging part of Also, fine: on the surface it looks fine, and you've used it before. I still think we should wait until other users request it, because so far you're the only user so perhaps you're an outlier? |
@FroMage try and implement range on the paging API of Panache, you'll see you can't naturally build one on the other. You can off the JPA API which does support range. |
That was a reply to " how can we do ranges if the paging part of Query does not support it? It's not clear to me." |
Yeah, I know they don't map, which is why I asked what the paging methods should do if we're ranging.
Sorry I can't parse that :( |
There is three popular ways to limit the list to a certain number of items and allow to fetch them:
The first is possible with the current API. If we don't want to provides a way to do it for a user, I may ask for a way to access the underlying Query before triggering, so adding a method So the user can do what he want with the Query, with this we don't need to implements various ne features on PanacheQuery that are wanted to have more customization on the query before triggering it (like the Having a way to use Panache direclty with a Query object instead if creating it will also works. This is also something requested in an existing issue. And it's something we do for PanacheMongo: |
That's not the issue. The issue is that if we allow for this (and again, I'm recommending to wait for a few more users asking for it), what will the behaviour of the current paging methods be? Methods like |
@FroMage yes, when we use range we should return a different interface: |
@FroMage I updated my proposal to return a You can see the changes in my improvements branch: master...loicmathieu:feat/panache-improvements |
I would also be interested in a standard |
I also have a use case for this, where the current paging approach makes it hard to implement. |
Also interested in this usage @loicmathieu |
@emmanuelbernard @FroMage I count 5 people asking for it now, should I propose an implementation ? |
yes I guess so |
Cool, I add it to my TODO list ;) |
Description
PanacheQuery support a paging mechanism that allow to fetch the result of a query page by page. This is handy to list all the result of a query but not to give an external application the capability to fetch all the results.
Moreover, paging is statefull as it implies to store the size of the page and the current page index.
In API developement, range query is often implemented by providing an extra query parameter
?range=0-10
, this is suitable to be used with HTTP range headers defined in the follwing RFC; https://tools.ietf.org/html/rfc7233Building such range capability where a user can ask for any range within the list of result is not suitable with the current paging implementation.
So I propose to add a PanacheQuery.range() method for this.
Implementation ideas
Add a
PanacheQuery.range(startIdx, endIdx)
method that will allow to setoffset
andlimit
on the generated SQL query as the current paging mechanism do.If it's OK, I can works on a PR for this.
The text was updated successfully, but these errors were encountered: