[erlang-questions] mnesia question

Chandru chandrashekhar.mullaparthi@REDACTED
Sun Sep 17 21:51:52 CEST 2017


Hi Lloyd,

If you are not querying by the primary key, you should use
mnesia:index_read/3 rather than mnesia:read/1

hth,
Chandru


On 17 September 2017 at 20:40, <lloyd@REDACTED> wrote:

> Hello,
>
> Life gets tricky in the literary world. Some authors use a pen name on
> their books rather than legal name. But it's quite possible for two
> different authors to use the same pen name. So pen name is not a good key
> to associate an author and a book. But ISBN does nicely.
>
> Email provides a convenient user name for access to a website. It
> minimizes the problem of two different people having the same user name.
>
> So in my user record I use email as the primary key. But, at creation of
> the record, I also generate a unique user_id in slot five in the user
> record. And I create an index to locate the user by user_id. This is handy,
> because I can use user_id to locate all of the user's books.
>
> So one would think that this query would work:
>
> get_member_by_member_id(MemberID) when is_list(MemberID)->
>     Query =
>         fun() ->
>             mnesia:read({?TABLE, MemberID})
>         end,
>     {atomic, Results} = mnesia:transaction(Query),
>     case length(Results) < 1 of
>        true  -> [];
>        false -> hd(Results)
>     end.
>
> But it doesn't. It returns an empty list.
>
> Not doubt I've forgotten something about mnesia or never learned it.
>
> Any help?
>
> Many thanks,
>
> LRP
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170917/e330390e/attachment.htm>


More information about the erlang-questions mailing list