gilbertosj
Sirs I’m trying to paginate, but I’m getting the following error.
A small note: There is no id column in the database.
Because this is an external query, I can not give mix ecto.create
Below I will show my files.
Error:
[info] Sent 500 in 1315ms
[error] pid<0.447.0> running GcallWeb.Endpoint (connection pid<0.433.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /relatorios
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Scrivener.Paginater not implemented for [%{accountcode: “”, amaflags: 3, …
struture
def list_cdr do
query_list_cdr = from e in Ecdr,
select: %{calldate: e.calldate, accountcode: e.accountcode, amaflags: e.amaflags, billsec: e.billsec, channel: e.channel, clid: e.clid, dcontext: e.dcontext, disposition: e.disposition, dst: e.dst, dstchannel: e.dstchannel, duration: e.duration, lastapp: e.lastapp, lastdata: e.lastdata, src: e.src, uniqueid: e.uniqueid, userfield: e.userfield}
Repo.all(query_list_cdr)
end
view
defmodule GcallWeb.EcdrView do
use GcallWeb, :view
import Scrivener.HTML
end
controller
def index(conn, params) do
cdr = Structure.list_cdr()
page = Structure.list_cdr
|> Repo.paginate(params)
render(conn, "index.html", cdr: page.entries, page: page)
end
config
config :scrivener_html,
routes_helper: GcallWeb.Router.Helpers
Template
<%= pagination_links @page, view_style: :bootstrap_v4, next: "Avançar", previous: "Voltar" %>
The only problem that happened was in this page, all the other pages that consult another table, which contains “id” works perfectly.
Trending in Questions
Other Trending Topics
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #iex
- #elixirconf-us
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kip
The error message doesn’t seem to relate to whether or not there is an
:idcolumn.You would need to put the call to
paginatebeforeRepo.allI think since the pagination for an ecto query is implemented as a sub-query.If you want to paginate after the query has returned - which what you are currently doing - then you would use the Scrivener.List package.
Just remove the call to
Repo.all/1and you should be good to go.kip
Using your code:
kip
One final thought. Your query has no
:orderexpression. Therefore the rows will be returned in a non-guaranteed order. Which will affect your pagination.Also note that
Scrivenerdoes anoffset/limitquery which has its own challenges, especially on large tables in Postgres. It also can create confusing results if rows are inserted ahead of the current “page”.You might consider reading the following for ideas and alternatives:
LostKobrakai
…, which also have their tradeoffs just like
offset/limitbased paginationkip
Agreed- each strategy has its pros and cons.
I usually prefer, for forward pagination, a simple
where unique_sequence_id > id_of_last_row_of_current_page limit page_sizebut there isn’t an obvious candidate in the provided query (as the author noted)gilbertosj
sorry for the delay,
everything went well.
Thank you