gilbertosj

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.

Showing Posts 1 to 6

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.

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
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:

LostKobrakai

LostKobrakai

…, which also have their tradeoffs just like offset/limit based pagination :slight_smile:

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)

gilbertosj

gilbertosj OP

sorry for the delay,
everything went well.
Thank you

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews