pilagod / gorm-cursor-paginator

A paginator doing cursor-based pagination based on GORM
https://github.com/pilagod/gorm-cursor-paginator
MIT License
192 stars 44 forks source link

Custom or more complex separator to separate field values in cursor #10

Closed WilfredGreyling closed 4 years ago

WilfredGreyling commented 4 years ago

Problem: I ran into an issue when my data contained a comma , in one of the key fields. The decodeBase64 function failed with an error.

This happens when the decodeBase64 function in the util.go file tries to reconstruct the original array. It uses the string.Split function and uses a hardcoded comma separator. If any key field data contains a comma, it breaks the function.

Suggestion: As the strings.Split function supports multi-character separators, why not use a more complex separator? Perhaps %|%

It should not have a significant impact on performance and will certainly reduce the risk of a collision when splitting the cursor to and from an array.

Perhaps also allow for a custom separator. Simplist solution, probably not the most elegant, could even be an environment var. If the pre-defined var exists, use it as the separator, else use the more complex %|%

pilagod commented 4 years ago

@WilfredGreyling Thanks for your suggestion, this is a definitely important issue to overcome.

I have came up with a way to totally get rid of separator problem, by storing all paginating values in an array, and then marshaling it to a json string. This would eliminate the need for separator.

I am going to handle this issue during these days, I will catch you up on any progress, thanks!

pilagod commented 4 years ago

@WilfredGreyling

I have released v1.2.0 to handle this issue, you can refer to #11 to see more details.

Feel free to open other issues if there is any problem, thanks 😃

WilfredGreyling commented 4 years ago

Thank you, will give it a go.