Skip to content
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

Pagination #84

Closed
Casperhr opened this issue Sep 5, 2016 · 8 comments
Closed

Pagination #84

Casperhr opened this issue Sep 5, 2016 · 8 comments
Labels
enhancement New feature or request

Comments

@Casperhr
Copy link
Member

Casperhr commented Sep 5, 2016

Like the collection, just with options for page=2 query

Add a pagination object to the response with

  • next page url
  • previous page url
  • current page
  • total pages
  • total count
  • count per page
@Casperhr Casperhr added the enhancement New feature or request label Sep 5, 2016
@mludi
Copy link

mludi commented Sep 15, 2016

That would be awesome.

@seivan
Copy link

seivan commented Sep 23, 2016

What's you're looking for is something like .limit()
This isn't something that should be in what is essentially the ORM.

@tanner0101
Copy link
Member

Fluent has limit already. Some web frameworks do even more in terms of paging though.

@hhanesand
Copy link

Maybe this is a bug better filed on Vapor's repository? Maybe some sort of middleware can be created that automatically adds pagination objects to the responses of certain requests?

@Casperhr
Copy link
Member Author

Casperhr commented Jan 3, 2017

@BrettRToomey Is working on this, should be ready soon!

@davidvpe
Copy link
Contributor

For some people that is having trouble with this, I just have made a simple workaround for my object named Offer being pageQuantity the quantity of elements per page and the pageNumber the one received on the request

        let count = try Offer.query().count()
        let amountOfPages = count/pageQuantity
        let limit = pageQuantity*pageNumber
        let query = try Offer.query().limit(limit)
        query.limit?.offset = (pageNumber-1)*pageQuantity
        let results = try query.run()

This approach actually performs two fetches to the DB, one for having the total amount of pages

Printing description of statement:
"SELECT COUNT() as _fluent_count FROM offers"
Printing description of statement:
"SELECT offers.
FROM offers LIMIT 20, 30"

@mludi
Copy link

mludi commented Jan 17, 2017

I made a simple wrapper around it few weeks ago https://github.com/mludi/VaporSimplePagination
I'm currently working on a new version :)

@BrettRToomey
Copy link
Contributor

BrettRToomey commented Jan 17, 2017

Here's what we ended up releasing at Nodes: https://github.com/nodes-vapor/paginator

It includes a Leaf tag and is bootstrap compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants