amnesia
amnesia copied to clipboard
[Request] Raw pattern matching support or raw wrapping support
To avoid the need for multiple index rows it would be ideal to be able to perform partial pattern matching on tuples
e.g.
:mnesia.match_object({AMNESIA.TABLE, {:tuple, :encoded, :cartesian, :index, :_})
But handling this would either require writing custom exquisite queries (? maybe)
or abandoning Amnesia.
It should be possible to provide a sort of last resort filtering library such that
Amnesia.Fragment.transaction do
Amnesia.wrapper do
:mnesia.match_object({AMNESIA.TABLE, {:tuple, :encoded, :cartesian, :index, :_})
end
end
where the wrapper logic determines if the inner term returns
{[values], continuation} (:mnesia.select) or [values] (:mnesia.match_object) or %end_of_table or RecordList
and populates the appropriate Amnesia.Table.Select{coerce: table_from_result, continuation: continuation_from_result, values: values_from_result} or appropriate error response.
Some sort of built in last resort macro or documentation for performing partial matches if possible directly using Amnesia/Exquisite would greatly improve the portability of Amnesia.
I'm happy to provide the code for such if the code maintainers have any guidelines, requirements for such a change, but I'd need guidance on any pure Amnesia solution here.
@note https://github.com/meh/amnesia/blob/211d98275c085a9e3049ccb8db8d29f76b3ffbfc/test/amnesia/database_test.exs#L242-L253
Did you try using Amnesia.Table.match?
Works a charm. would you like me to push a doc section on this method. It's a common use case for optimized querying against a ordered_set table to the best of my understanding. And others have seemed to be confused by the proper syntax here.
match = [date: {year, month, iso_week, :_}]
Calendar.Entries.match(match)
Sure :)