如何为 Erlang mnesia 编写 "in" 查询?
How to write "in" query for Erlang mnesia?
我有失忆症 table,比方说 employee
。我需要找到名字在 EmployeeNameList = ["Erlich", "Richard", "Gilfoyle", "Dinesh"]
中的所有员工记录。有没有办法使用 mnesia:select
或其他函数来做到这一点?
遵循 Mnesia 的文档
可以这样做:
get_employees_by_name(NameList) ->
MatchHead = #employee{name = '', _ = '_'},
Result = '$_'
MatchSpec = [ { MatchHead, [{'=:=', '', Name}], [Result]} || Name <- NameList ],
F = fun() ->
mnesia:select(employee, MatchSpec)
end,
{atomic, Result} = mnesia:transaction(F),
Result.
我有失忆症 table,比方说 employee
。我需要找到名字在 EmployeeNameList = ["Erlich", "Richard", "Gilfoyle", "Dinesh"]
中的所有员工记录。有没有办法使用 mnesia:select
或其他函数来做到这一点?
遵循 Mnesia 的文档 可以这样做:
get_employees_by_name(NameList) ->
MatchHead = #employee{name = '', _ = '_'},
Result = '$_'
MatchSpec = [ { MatchHead, [{'=:=', '', Name}], [Result]} || Name <- NameList ],
F = fun() ->
mnesia:select(employee, MatchSpec)
end,
{atomic, Result} = mnesia:transaction(F),
Result.