Hello,
This is my function
def get(_role) do
match_pattern =
{MishkaAuth.User.Users, :_, :_, :_, :_, :_, :_, :_, :_, :"$9", :_, :_, :_, :_, :_}
guard = []
result_fun = [:"$$"]
# Number of records to fetch
limit = 1
:mnesia.transaction(fn ->
case :mnesia.select(__MODULE__, [{match_pattern, guard, result_fun}], limit, :read) do
{matches, cont} when is_list(matches) and matches != [] ->
# Handle the fetched matches and the continuation for potential future use
{:ok, matches, cont}
_ ->
# Handle the case where no matches are found or an error occurs
{:error, :no_matches}
end
end)
end
When I call it like this
{:atomic, {:ok, matches, cont}} = MishkaAuth.User.Users.get :role
and put the cont into this
:mnesia.transaction(fn -> :mnesia.select(cont) end)
I got this error
{:aborted, :wrong_transaction}
I just want to show next page and every page show 1 record
Could you help me in this Thanks
Updated:
In a transaction, if I do it, it goes to the next page, but the problem is that the user may want the results and then click again.
So, every time the user requests, I have to create a transaction from the beginning and run it 4 times to reach page 4?
Not a good way to paginate?
for example:
{_record, cont} =
:mnesia.activity(:async_dirty, fn ->
:mnesia.select(__MODULE__, [{match_pattern, guard, result_fun}], limit, :read)
end)
:mnesia.activity(:async_dirty, fn -> :mnesia.select(cont) end)
if I need to go page 4, I need to do something like this, it is an abstraction
{_record, cont} =
:mnesia.activity(:async_dirty, fn ->
:mnesia.select(__MODULE__, [{match_pattern, guard, result_fun}], limit, :read)
end)
{_record, cont1} = :mnesia.activity(:async_dirty, fn -> :mnesia.select(cont) end)
{_record, cont2} = :mnesia.activity(:async_dirty, fn -> :mnesia.select(cont1) end)
{_record, cont3} = :mnesia.activity(:async_dirty, fn -> :mnesia.select(cont2) end)
It is just useful for Infinite Scroll
, not Numerical pagination