-
Notifications
You must be signed in to change notification settings - Fork 44
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
feat: add support for custom encoder/decoder implementations #66
Conversation
I didn't think of it before, this sounds a good idea to me 👍 Since encoding and decoding must be paired in order to function well, I would suggest to design a single interface, for example, Besides that, another small question is that I don't find which line uses the |
I did initially use a single strict but then spun it into two for flexibility - but in reality it was probably overkill, I can merge them into one easily enough. I need to check where |
Hi, Sorry completely forgot about this until I needed it earlier today. I've refactored and squashed the previous commits. The new interface for supplying a customer encoder/decoder is Internally we still use the Also |
@sashahilton00 Thanks for your follow-up 🙌 Based on your work, in my opinion it could be better to further decouple the creation of codec from this library, to make codec a pure interface. I wrote an example to illustrate the design: sashahilton00/gorm-cursor-paginator@master...pilagod:gorm-cursor-paginator:cursor-codec If you do agree with the suggestion, please feel free to pick up any commits from that branch, and also help us to update the document accordingly. Thank you so much 🙂 |
@pilagod decoupling the creation of the codec is cleaner, though it is a breaking change. If you don't mind that I'll pull the changes you made in, I might also add a base62 codec to be available out of the box, as base64 is not url safe, which was the original reason for this codec change. There is another change I was thinking about but didn't implement because it was breaking - incorporating the paging direction into the cursor itself - so instead of passing a query param such as As an example of what I mean, https://github.com/djrobstep/sqlakeyset does this. |
To my understanding, both versions (codec factory / codec interface) would not be a breaking change, since the new option is with proper default value which is backward-compatible, it should not affect current users. One evidence is that all tests written before this patch would be still passed. Not sure if I missed something. Would be glad to know more details about your concern of the breaking changes. And the new cursor idea sounds worth further studying to me. I would need some time to get a thorough understanding of it, and we can consider it in the future PR 💪 Really appreciate your opinions, they are quite inspiring. 🙌 |
Good point, I didn't fully review the commit you provided, on closer inspection it shouldn't be breaking. I'll pull the changes in when I get a moment and update the docs. I may add the direction change to the cursor in a separate PR if I get a moment, I'll keep this one just focused on the codec. |
Thank you so much 💪 Since changing the cursor direction usage would cause a breaking change, I would suggest that we could discuss further in issue before putting it into implementation. |
Sorry about the delay, I completely forgot about this, will try and implement tomorrow. |
No worry. This is not in a hurry, just taking your time. |
Have pulled in the changes and updated the docs 👍 |
Pull Request Test Coverage Report for Build 11074526361Details
💛 - Coveralls |
Sorry for the late reply, I am swamped with work recently. This PR looks good to me, though I come up with a few ideas to refine the whole structure of the document, I will merge this PR first and release a new version after the document refinement. Really appreciating your new feature exploration in the #69, I may need some more time to check it closely in order to give out helpful feedback. |
This pull request adds the ability to provider custom cursor encoder/decoder implementations.
It is a non-breaking change, adding two new config options
CursorEncoderFactory
andCursorDecoderFactory
that if defined will be used for encoding/decoding the cursor.Internally the library has been slightly modified to use interfaces for encoding/decoding as opposed to using the hardcoded cursor package. If no implementation is provided the existing cursor implementation is used.