Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  erlyweb 7.1 with mnesia, the musician example works.

frankpengca
Posted: Sun Jul 19, 2009 5:15 am Reply with quote
Joined: 12 Jul 2009 Posts: 4
Some Japanese made the erlyweb worked with mnesia.

Here is the url link.

http://lab.klab.org/wiki/ErlyWeb%E3%81%A7mnesia%E3%82%92%E4%BD%BF%E3%81%86

He is using Windows.

I made it worked on FreeBSD.

The erlang version is 5.7.2. Yaws is 1.84. Erlyweb is 7.1

Here are the steps:

1, modify the erlyweb source file. erlydb_mnesia.erl

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


get_metadata(_Options) ->
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).

2, Change the yaws.conf file like this:

docroot = "/usr/local/music/www"
appmods = </usr/local/music, erlyweb>
<opaque>
appname = music
</opaque>
3, Start erl like this:

erl -sname music -mnesia dir '"/var/spool/yaws"'

Since there is no directory /usr/local/music for now, you cannot start yaws -i. All other tutorials say start yaws -i now, I cannot make it work now.

4, Run the following commands:
(If you know how to write a script and run under the erlang shell, please let us know.)

mnesia:start().

mnesia:change_table_copy_type(schema,node(),disc_copies).

mnesia:create_table(counter, [{disc_copies, [node()]},{attributes,[key, counter]}]).

mnesia:create_table(musician,[{disc_copies, node()]},{attributes,
[id,name,birth_date,instrument,bio]},user_properties,[{id,{integer,
undefined}, false, primary, undefined, identity, integer},{name,
{varchar, 20}, false, undefined, undefined, undefined, atom},
{birth_date, {datetime, undefined}, true, undefined, undefined,
undefined, undefined},{instrument, {enum, ["guitar", "piano", "drums",
"vocals"]}, true, undefined, undefined, undefined, undefined}]}]).

The bio is missing. I do not know why it works.

erlyweb:create_app("music","/usr/local").

erlydb:start(mnesia).

erlyweb:create_component("musician", "/usr/local/music").

erlyweb:compile("/usr/local/music", [{erlydb_driver, mnesia}]).

Rec = musician:new().

Rec1 = musician:set_fields(Rec,[{name,"John Lennon"},{birth_date,
"1940/10/9"},{instrument, "vocals"},{bio,"An iconic English 20th
century rock and roll songwriter and singer..."}]).


Rec2 = musician:set_fields(Rec,[{name,"Paul McCartney"},{birth_date,
"1942/6/18"},{instrument, "piano"},{bio, "Sir James Paul McCartney is
a popular Grammy Award-winning English artist..."}]).

musician:insert(Rec1).

musician:insert(Rec2).

q().

5, Now you can start yaws -i

yaws -i

erlydb:start(mnesia).

erlyweb:compile("/usr/local/music", [{erlydb_driver, mnesia}]).

6, find a web browser and fire:
http://192.168.0.1/music/musician

This is the result:

music app
create new

Records of 'musician'
id name birth_date instrument bio
1 'John Lennon' 1940/10/9 vocals An iconic English 20th century rock and roll songwriter and singer...
2 'Paul McCartney' 1942/6/18 piano Sir James Paul McCartney is a popular Grammy Award-winning English artist...

powered by ErlyWeb / Yaws


The submit button is not working. It is not implemented.
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