vapor-community / pagination

Simple Vapor 3 Pagination
MIT License
64 stars 15 forks source link

Support database connection #15

Closed staffler-xyz closed 6 years ago

staffler-xyz commented 6 years ago

It should be possible to use pagination with a pooled connection (as this is required on some hosts, e.g. heroku):

func index(_ request: Request) throws -> Future<Paginated<Item>> {
        return request.withPooledConnection(to: .psql) { connection in
            return try Item.query(on: connection).paginate(for: request)
        }
    }

It would be nice to maybe have an optional parameter connection: Database that can be passe to the paginate function.

anthonycastelli commented 6 years ago

The reason the request is there is to help generate the missing pieces for the request. What it does is just read the query parameters for the page and count to allow it to perform the fetch for the given page.

https://github.com/vapor-community/pagination/blob/d018e2a02ed94536ad494ff750057990e8ae1acf/Sources/Pagination/QueryBuilder%2BPaginatable.swift#L50-L67

Implementing the database connection isn't need for something like this, unless I am miss understanding you. Can you maybe elaborate a bit more? 🙂

staffler-xyz commented 6 years ago

Oh i see, it is already using the database connection - thanks for your answer!