I want to get the last table entry submitted using Repo.one
I have a simple Liveview that I created without the generator and I have another collection of non-liveview data and routes that I did create using a generator. The generated table is called Testbeds (all code below). I want to get the last table entry submitted to Testbeds and I am trying to use Repo.one to do this. I could do it on the Liveview client but I am curious what I am doing wrong and why Repo.one is not working. I am using the function Testbed.get_last()
Code
defmodule App.Testbeds do
@moduledoc ββ"
The Testbeds context.
ββ"
import Ecto.Query, warn: false
alias App.Repo
alias App.Testbeds.Testbed
# data ....
def get_last() do
Repo.one(from x in App.Testbeds, order_by: [desc: x.id], limit: 1)
end
end
Liveview
defmodule AppWeb.PageLive do
use AppWeb, :live_view
alias App.Testbeds
def mount(_params, _session, socket) do
{:ok, assign(socket, testbed: Testbeds.get_last())}
end
def render(assigns) do
~H"""
<%= assigns.testbed.name%>
"""
end
end
Error
function App.Testbeds.__schema__/1 is undefined or private