amnesia icon indicating copy to clipboard operation
amnesia copied to clipboard

[Request] Raw pattern matching support or raw wrapping support

Open noizu opened this issue 8 years ago • 4 comments

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.

noizu avatar Feb 21 '17 14:02 noizu

@note https://github.com/meh/amnesia/blob/211d98275c085a9e3049ccb8db8d29f76b3ffbfc/test/amnesia/database_test.exs#L242-L253

noizu avatar Feb 21 '17 15:02 noizu

Did you try using Amnesia.Table.match?

meh avatar Feb 21 '17 17:02 meh

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)

noizu avatar Feb 21 '17 20:02 noizu

Sure :)

meh avatar Feb 22 '17 06:02 meh