gilbertosj

gilbertosj

Problem in paging, table without id

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.

Marked As Solved

kip

kip

ex_cldr Core Team

Using your code:

def list_cdr do
  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
  }

# Remove this line
# Repo.all(query_list_cdr)
end

Also Liked

kip

kip

ex_cldr Core Team

One final thought. Your query has no :order expression. Therefore the rows will be returned in a non-guaranteed order. Which will affect your pagination.

Also note that Scrivener does an offset/limit query 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:

kip

kip

ex_cldr Core Team

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_size but there isn’t an obvious candidate in the provided query (as the author noted)

kip

kip

ex_cldr Core Team

The error message doesn’t seem to relate to whether or not there is an :id column.

You would need to put the call to paginate before Repo.all I 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/1 and you should be good to go.

Last Post!

gilbertosj

gilbertosj

sorry for the delay,
everything went well.
Thank you

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement