Closed mikkelu closed 5 years ago
This is some really nice work here! π
I haven't tested this, but everything looks great and is ready to merge I think. Just to clarify, this wouldn't break any current implementations?
Edit: This looks like a great foundation for a 2.0.0 release. I've created a Milestone of things I'd like in 2.0.0
Thanks! Yes, I also think it would be great for a 2.0.0 release π
I am almost certain that it won't break any current implementations however, I am not 100% sure as our internal usage of this, is based on the changes in this PR.
We just hit another interesting obstacle.
We need to do some custom sorting, but we cannot call that on req.paginate(on: req, transform{})
, and we end up with conflicts between our custom sorts with the default sort.
I thought that maybe we should, for the pagination with the transformation closure, remove the sorting, because users can do their sorting in the transformation closure as they please.
This will allow for even more customization and still keep the default sorting for basic pagination (queries without the transformation closure handler).
What do you think?
@mikkelu I like that approach there. If you use the closure, everything is up to the user to customize then. That allows the extreme flexibility and control.
I have been chatting with @tanner0101 about this and we're going to work on merging this into Fluent itself, so within this pull request, we should think about how we can split this up between the core foundation and the fluff that the custom retransform closure will allow.
@anthonycastelli @tanner0101 that sounds like a great idea. I think it would be an awesome feature for Fluent. What are your initial thoughts on how to proceed?
Well, looking over your pull request, we'd want to split it up based on the core functionality and then any additional wrappers & extensions to implement the custom transformations. I have some time this weekend so I will sit down and start looking over it all and seeing how we can split it up. Just a quick overlook of it all, we shouldn't have an issue doing it.
@mikkelu I've been using your branch since it was posted, cause it was what I was looking for, and it has been cake to use. Amazing job!
Im gonna merge this into the master branch so it makes it easier for me to start working on the migration for Fluent 4
I'll also release a pre-release version of this from this master branch so everyone can start using it if they wish
Cool. Let me know if you need any help @anthonycastelli π
Will do @mikkelu π
First of all, thanks for this great package. I have been using it a lot. However, I ran into some difficulties when trying to do more advanced stuff like custom response types and advanced queries, e.g., joins, also decode, etc.
I want to apologize for this PR becoming so massive, but I created this for our own API's, and I ended up writing a lot on top of the current implementation to allow for customizations. I did not have time to break this into smaller chunks, and this PR would probably require the package to do a bump in major.
This implementation is tested and works in production, but I think we should use this PR to discuss how a Pagination 2.0.0 should look. Nonetheless, here are the changes:
Content
. Next, I could introduce a transformation closure in the page functions:transform: @escaping (QueryBuilder) throws -> Future<[R]>
which now allows us to transform the underlying query builder to an actual result and hence transform the result. This allows us to do this (which solves #11 #12 ):( -> Future<Paginated> )