Erlang/OTP Forums

Author Message

<  Erlyweb mailing list  ~  first pass at using mnesia problems

jeffm
Posted: Thu Nov 13, 2008 5:13 am Reply with quote
User Joined: 29 Sep 2008 Posts: 43
The error below is the result of trying to use mnesia as the back end
database. Mnesia was chosen for this as it was already used for another
erlang application and this is suppose to be the web front end to it.
The table is created successfully using similar code to that defined
below (the record_info/2 function call is replaced manually with [id,
username, password, roles] and Nodes is replaced by [nodes()] to run it
from the shell). The module is otherwise empty except for the copiler
directives. When it comes to compiling it complains of "no function
clause matching" (see further down in this message for the dump). Any
thought or suggestions on how to correct this?

Also, what should the {Field, {Type, Modifier}, Null, Key, Default,
Extra, MnesiaType} be for record element roles if it's to be a list of
atoms?

Jeff.

%% mgr_user.erl
-record(mgr_user, {
id,
username,
password,
roles = [] %% roles take the form
module_action
}).


create_table(Nodes) when is_list(Nodes) ->
mnesia:create_table(counter, [{disc_copies, Nodes}, {attributes,
[key, counter]}]),
mnesia:create_table(mgr_user, [{disc_copies, Nodes},
{attributes, record_info(fields,
mgr_user)},
{user_properties,
[
%% {Field, {Type, Modifier},
Null, Key, Default, Extra, MnesiaType}
%% {id,
{integer,undefined},false,primary,undefined,undefined,integer},
{username,
{varchar,undefined},false,undefined,undefined,undefined,list},
{password,
{varchar,undefined},false,undefined,undefined,undefined,list},
{roles,
{varchar,undefined},false,undefined,undefined,undefined,list}
]
}
]),
mnesia:dirty_update_counter(counter, mgr_user, 1).

> erlyweb:compile("mgr_erlyweb",[{erlydb_driver, mnesia}]).
debug:erlyweb_compile:379: Compiling Erlang file "mgr_user_controller"
debug:erlyweb_compile:379: Compiling Erlang file "mgr_user"
debug:erlyweb_compile:114: Generating ErlyDB code for models:
"mgr_user.erl "
debug:erlydb:355:

--- To skip foreign key checks, compile with the {skip_fk_checks, true}
option


** exception error: no function clause matching
gb_trees:lookup_1(mgr_user,
{3,
{mgr_user,

[{erlydb_field,username,"username",<<"username">>,

varchar,undefined,binary,text_field,false,undefined,
undefined,undefined,undefined},
....
in function erlydb:gen_module_code/5
in call from lists:foreach/2
in call from erlyweb_compile:compile/2


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
View user's profile Send private message
Guest
Posted: Thu Nov 13, 2008 11:03 am Reply with quote
Guest
Jeff,

If you are using erlydb 0.7.x try editing the mnesia driver source
file src/erlydb/erlydb_mnesia.erl, look for the function get_metadata/
1 and change the return value from {ok,Tree} to Tree. That should
solve your compile problem (after recompiling erlydb of course).

From 0.6 to 0.7 there was an internal api change and the mnesia
driver got left behind -- I guess not to many people are using erlyweb
with the mnesia driver Sad There was a patch for this but I'm not sure
if it made it to the main stream.

Hope this helps,

John


On Nov 13, 2008, at 2:17 PM, jm wrote:

>
>
> The error below is the result of trying to use mnesia as the back end
> database. Mnesia was chosen for this as it was already used for
> another
> erlang application and this is suppose to be the web front end to it.
> The table is created successfully using similar code to that defined
> below (the record_info/2 function call is replaced manually with [id,
> username, password, roles] and Nodes is replaced by [nodes()] to run
> it
> from the shell). The module is otherwise empty except for the copiler
> directives. When it comes to compiling it complains of "no function
> clause matching" (see further down in this message for the dump). Any
> thought or suggestions on how to correct this?
>
> Also, what should the {Field, {Type, Modifier}, Null, Key, Default,
> Extra, MnesiaType} be for record element roles if it's to be a list of
> atoms?
>
> Jeff.
>
> %% mgr_user.erl
> -record(mgr_user, {
> id,
> username,
> password,
> roles = [] %% roles take the form
> module_action
> }).
>
>
> create_table(Nodes) when is_list(Nodes) ->
> mnesia:create_table(counter, [{disc_copies, Nodes}, {attributes,
> [key, counter]}]),
> mnesia:create_table(mgr_user, [{disc_copies, Nodes},
> {attributes, record_info(fields,
> mgr_user)},
> {user_properties,
> [
> %% {Field, {Type, Modifier},
> Null, Key, Default, Extra, MnesiaType}
> %% {id,
> {integer,undefined},false,primary,undefined,undefined,integer},
> {username,
> {varchar,undefined},false,undefined,undefined,undefined,list},
> {password,
> {varchar,undefined},false,undefined,undefined,undefined,list},
> {roles,
> {varchar,undefined},false,undefined,undefined,undefined,list}
> ]
> }
> ]),
> mnesia:dirty_update_counter(counter, mgr_user, 1).
>
>> erlyweb:compile("mgr_erlyweb",[{erlydb_driver, mnesia}]).
> debug:erlyweb_compile:379: Compiling Erlang file "mgr_user_controller"
> debug:erlyweb_compile:379: Compiling Erlang file "mgr_user"
> debug:erlyweb_compile:114: Generating ErlyDB code for models:
> "mgr_user.erl "
> debug:erlydb:355:
>
> --- To skip foreign key checks, compile with the {skip_fk_checks,
> true}
> option
>
>
> ** exception error: no function clause matching
> gb_trees:lookup_1(mgr_user,
> {3,
> {mgr_user,
>
> [{erlydb_field,username,"username",<<"username">>,
>
> varchar,undefined,binary,text_field,false,undefined,
>
> undefined,undefined,undefined},
> ....
> in function erlydb:gen_module_code/5
> in call from lists:foreach/2
> in call from erlyweb_compile:compile/2
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
Guest
Posted: Thu Nov 13, 2008 6:45 pm Reply with quote
Guest
I'm trying to use it as well. I just tracked down the same problem.

Tree is unnecessary so here's what I have for
erlydb_mnesia:get_metadata/1.

get_metadata(_Options) ->
% NOTE Integration with mnesia_rdbms would be interesting...
Tables = mnesia:system_info(tables) -- [schema],
lists:foldl(
fun(Table, TablesTree) ->
gb_trees:enter(Table, get_metadata(Table, table_fields
(Table)), TablesTree)
end, gb_trees:empty(), Tables).


/michael.

On Nov 13, 6:02
jeffm
Posted: Fri Nov 14, 2008 3:50 am Reply with quote
User Joined: 29 Sep 2008 Posts: 43
Thank's guys. That's works. I should have specified that I was/am using
version 7.1.1. Bad form on my part there.


Jeff.

Michael Mullis wrote:
> I'm trying to use it as well. I just tracked down the same problem.
>

> /michael.
>
> On Nov 13, 6:02 am, John Webb <jw...@gol.com> wrote:
>
>> Jeff,
>>
>> If you are using erlydb 0.7.x try editing the mnesia driver source
>> file src/erlydb/erlydb_mnesia.erl, look for the function get_metadata/
>> 1 and change the return value from {ok,Tree} to Tree. That should
>> solve your compile problem (after recompiling erlydb of course).
>>
>>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum