-
Notifications
You must be signed in to change notification settings - Fork 93
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
Cursor decode does not work for custom sort field with fragment
#196
Comments
While this is not resolved, temporary solution can be a using of computed columns (like views for tables) that is not stored on disk
However, does not properly with |
On what version have you tried this ? I've encountered same problem, but it turns out that I was using not latest version. On main branch this version is working (run inside paginator_test.exs) test "expression based field is properly encoded and decoded" do
customers =
["A customer", "b customer", "C customer", "d customer"]
|> Enum.map(&%{name: &1, internal_uuid: Ecto.UUID.generate()})
|> Enum.map(&insert(:customer, &1))
paginate_opts = [
limit: 1,
cursor_fields: [
{
{:name,
fn ->
Ecto.Query.dynamic(
[customer],
fragment("lower(?)", customer.name)
)
end},
:desc
}
],
fetch_cursor_value_fun: fn schema, :name ->
schema
|> Map.get(:name)
|> String.downcase()
end
]
assert %Page{entries: [%Customer{name: "d customer"}], metadata: metadata} =
Customer
|> order_by([customer], desc: fragment("lower(?)", customer.name))
|> Repo.paginate(paginate_opts)
paginate_opts = Keyword.put(paginate_opts, :after, metadata.after)
assert %Page{entries: [%Customer{name: "Charlie"}], metadata: metadata} =
Customer
|> order_by([customer], desc: fragment("lower(?)", customer.name))
|> Repo.paginate(paginate_opts)
paginate_opts = Keyword.put(paginate_opts, :after, metadata.after)
assert %Page{entries: [%Customer{name: "C customer"}], metadata: metadata} =
Customer
|> order_by([customer], desc: fragment("lower(?)", customer.name))
|> Repo.paginate(paginate_opts)
paginate_opts =
paginate_opts
|> Keyword.put(:before, metadata.before)
|> Keyword.put(:after, nil)
assert %Page{entries: [%Customer{name: "Charlie"}]} =
Customer
|> order_by([customer], desc: fragment("lower(?)", customer.name))
|> Repo.paginate(paginate_opts)
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Custom field with
fragment
, passed with anonymous functionCall without after_cursor is working:
However, when paginate with
after
,&Paginator.Cursor.decode/1
will fail:Output:
It is documented already:
https://github.com/duffelhq/paginator/pull/166/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R190
Function
is not safe term to decode in
Paginator.Cursor
, deps/paginator/lib/paginator/cursor.ex:9Idea: mb to support {:mfa, module, functions, args} way to decode
after_cursor
The text was updated successfully, but these errors were encountered: