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

Add support for cursor custom conversion #62

Closed
wants to merge 1 commit into from

Conversation

fuelen
Copy link

@fuelen fuelen commented Apr 3, 2019

Related to this: #61
This PR solves my issue with minimal changes
I've added the following lines to my application:

defimpl Paginator.Cursor.Encode, for: DateTime do
  def convert(term), do: {:dt, DateTime.to_unix(term, :microsecond)}
end

defimpl Paginator.Cursor.Decode, for: Tuple do
  def convert({:dt, unix_timestamp}), do: DateTime.from_unix!(unix_timestamp, :microsecond)
end
> datetime = DateTime.utc_now
#DateTime<2019-04-03 11:25:47.435854Z>

# before:
> Paginator.Cursor.encode([datetime])
"g2wAAAABdAAAAA1kAApfX3N0cnVjdF9fZAAPRWxpeGlyLkRhdGVUaW1lZAAIY2FsZW5kYXJkABNFbGl4aXIuQ2FsZW5kYXIuSVNPZAADZGF5YQNkAARob3VyYQtkAAttaWNyb3NlY29uZGgCYgAGpo5hBmQABm1pbnV0ZWEZZAAFbW9udGhhBGQABnNlY29uZGEvZAAKc3RkX29mZnNldGEAZAAJdGltZV96b25lbQAAAAdFdGMvVVRDZAAKdXRjX29mZnNldGEAZAAEeWVhcmIAAAfjZAAJem9uZV9hYmJybQAAAANVVENq"

# after:
> Paginator.Cursor.encode([datetime])                                                        
"g2wAAAABaAJkAAJkdG4HAE7r4IOehQVq"

The idea with custom cursor module from #9 looks more flexible, but there is no moving for a long time there, it is a bit outdated and I found it only during preparing this PR.

Base automatically changed from master to main January 26, 2021 17:52
@sgerrand
Copy link
Contributor

sgerrand commented Nov 3, 2021

Hello @fuelen and thank you for creating this submission. Would you please rebase your changes against the main branch to resolve the existing conflicts.

@fuelen
Copy link
Author

fuelen commented Nov 3, 2021

Hi @sgerrand

I can do this, but is it worth? Maybe it is better to go with #9?
I didn't close this PR in order to have a quick working solution for others and because some of my apps rely on this branch.

WDYT?

@sgerrand
Copy link
Contributor

sgerrand commented Nov 3, 2021

Maybe it is better to go with #9?

🙆 I'll try to bring that up-to-date later this week.

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

Successfully merging this pull request may close these issues.

2 participants