Closed Korbin73 closed 5 years ago
Nevermind. I looks like I can turn coercion off and handle the end_of_table result myself.
Hey @Korbin73, this might still be a potential bug. Can you please post details about your table structure and the query you executed?
Sure, it's quite simple actually. I have a simple table:
defmodule Request.Record do
use Memento.Table, attributes: [:url, :response]
end
All I did was do a select that where I knew that the it would not return anything from Mnesia:
Memento.transaction! fn ->
Memento.Query.select(Request.Record, {:==, url, "gibberish"}, [limit: 1])
end
After looking at the source, I noticed that I could turn off coercion so the coerce_records function isn't called. I was expecting on getting an empty record when it was on instead of an exception, but turning off coercion and matching the result myself is pretty easy.
Yep this was in fact a bug in the code. It should've returned an empty list when no records match. I just published a new release (v0.3.1
) to hex.pm with the bugfix.
Thanks for reporting this!
I noticed that if a query fails to return any records, I get the following error: ** (FunctionClauseError) no function clause matching in Memento.Query.coerce_records/1 (memento) lib/memento/query/query.ex:663: Memento.Query.coerce_records(:"$end_of_table")
However calling Mnesia directly, I get the standard message of: {:atomic, []} that I can easily pattern match on.