mnesia question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

mnesia question

Lloyd R. Prentice-2
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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: mnesia question

Chandru-4
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, <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions