Problems with mnemosyne
Samuel Rivas
samuel@REDACTED
Fri Apr 11 16:49:14 CEST 2003
On Fri, 11 Apr 2003, 10:07 +0200, Dan Gudmundsson wrote:
>
> Can you post the record definitions and the
> mnemosyne query.
>
Of course:
The records:
-----------
-record(movie,
{id,
file,
genre_id,
year,
new = true
}).
-record(movie_info,
{movie_id, %% References movie.id
lang_id,
synopsys,
title
}).
-record(shown_movie,
{set_top_box_id,
name, %% User name
movie_id
}).
Table creation functions:
------------------------
init_movie() ->
{atomic, ok} = mnesia:create_table(movie,
[{disc_copies, [node()]},
{attributes, record_info(fields, movie)}]).
init_movie_info() ->
{atomic, ok} = mnesia:create_table(movie_info,
[{disc_copies, [node()]},
{type, bag},
{index, [lang_id]},
{attributes, record_info(fields, movie_info)}]).
init_shown_movie() ->
{atomic, ok} = mnesia:create_table(shown_movie,
[{disc_copies, [node()]},
{type, bag},
{index, [name]},
{attributes, record_info(fields, shown_movie)}]).
And the query:
-------------
get_shown_movies(LangId, StpbxId, User, GenreId) when list(LangId),
list(StpbxId),
record(User, user),
atom(GenreId) ->
Q = query
[{M, MI} || M <- table(movie),
MI <- table(movie_info),
ShownMovie <- table(shown_movie),
M.genre_id = GenreId,
MI.movie_id = M.id,
MI.lang_id = LangId,
ShownMovie.set_top_box_id = StpxId,
ShownMovie.name = User#user.name,
ShownMovie.movie_id = M.id]
end,
F = fun() ->
mnemosyne:eval(Q)
end,
mnesia:transaction(F).
I've solved the problem grouping the table keys on a single tuple,
{set_top_box_id, name} and {movie_id, lang_id} for both
shown_movie and movie_info tables. This elimates the needed to
add extra indices.
Regards
--
---------------------
| Samuel |
---------------------
More information about the erlang-questions
mailing list