Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Raw pattern matching support or raw wrapping support #62

Open
noizu opened this issue Feb 21, 2017 · 4 comments
Open

[Request] Raw pattern matching support or raw wrapping support #62

noizu opened this issue Feb 21, 2017 · 4 comments

Comments

@noizu
Copy link

noizu commented Feb 21, 2017

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
Copy link
Author

noizu commented Feb 21, 2017

@note

assert(Amnesia.transaction! do
selection = User.select(1, [{ { User, :'$1', :_, :_ }, [], [:'$1'] }])
assert Selection.values(selection) == [1]
selection = Selection.next(selection)
assert Selection.values(selection) == [2]
selection = Selection.next(selection)
assert Selection.values(selection) == [3]
assert Selection.next(selection) == nil
end == true)

@meh
Copy link
Owner

meh commented Feb 21, 2017

Did you try using Amnesia.Table.match?

@noizu
Copy link
Author

noizu commented Feb 21, 2017

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)

@meh
Copy link
Owner

meh commented Feb 22, 2017

Sure :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants