Open table in another node's database

View: New views
5 Messages — Rating Filter:   Alert me  

Open table in another node's database

by Januar V. Simarmata (G!) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have created an Mnesia database in node' jvs01'.

Then I run Yaws with 'nohost@nonode'.

Is there any way to open the table in node jvs01 from Yaws script?

Thanks for the hints,

--
Januar V. Simarmata
Follow me on Twitter @januarvs

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

Re: Open table in another node's database

by Claes Wikstrom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Januar V. Simarmata (G!) wrote:
> Hi,
>
> I have created an Mnesia database in node' jvs01'.
>
> Then I run Yaws with 'nohost@nonode'.
>
> Is there any way to open the table in node jvs01 from Yaws script?

Not if you want to use distributed erlang. If you - as you write -
choose to not use distribution, you must set up regular sockets
to the node and send/receive term_to_binary/1 terms on the socket.

/klacke

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

Parent Message unknown Re: Open table in another node's database

by Januar V. Simarmata (G!) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Not if you want to use distributed erlang.
does it mean that it is possible with distributed erlang.

Currently I have such code:

<erl>
-include_lib("stdlib/include/
qlc.hrl").

%%-include("common.hrl").
%%-include("records.hrl").

do(Q) ->
    F = fun() -> qlc:e(Q) end,
    {atomic, Val} = mnesia:transaction(F),
    Val.

keyval(K,L) ->
    {value, {K, V}} = lists:keysearch(K,1,L),
    V.

-record(suggest, {prefix, top_words}).

out(A) ->
    Arg = yaws_api:parse_query(A),

    %% search_words
    Prefix = keyval("search_words", Arg),
    SearchWords = do(qlc:q([X#suggest.top_words || X <- mnesia:table(suggest),
                            X#suggest.prefix =:= Prefix ])),

    {ehtml,
       {pre,[], f("~p", [SearchWords])}
    }.
</erl>


Will you please show a simple example to do distributed erlang?

Thanks,
~JVS


On Wed, Aug 26, 2009 at 5:30 PM, Januar V. Simarmata (G!) <januarvs@...> wrote:


On Sun, Aug 23, 2009 at 4:24 AM, Claes Wikstrom <klacke@...> wrote:
Januar V. Simarmata (G!) wrote:
Hi,

I have created an Mnesia database in node' jvs01'.

Then I run Yaws with 'nohost@nonode'.

Is there any way to open the table in node jvs01 from Yaws script?

Not if you want to use distributed erlang. If you - as you write -
choose to not use distribution, you must set up regular sockets
to the node and send/receive term_to_binary/1 terms on the socket.

/klacke



--
Januar V. Simarmata



--
Januar V. Simarmata

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

Re: Open table in another node's database

by Claes Wikstrom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Januar V. Simarmata (G!) wrote:

>  > Not if you want to use distributed erlang.
> does it mean that it is possible with distributed erlang.
>
> Currently I have such code:
>
> <erl>
> -include_lib("stdlib/include/
>
>     qlc.hrl").
>
>     %%-include("common.hrl").
>     %%-include("records.hrl").
>
>     do(Q) ->
>         F = fun() -> qlc:e(Q) end,
>         {atomic, Val} = mnesia:transaction(F),
>         Val.
>




It would then have to be:

rpc:call(Node, ?MODULE, do, [Q]).

That way the code would be executed on the remote
node and the reply returned to your web code.

/klacke

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

Re: Open table in another node's database

by Claes Wikstrom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Claes Wikström wrote:

>
>
> It would then have to be:
>
> rpc:call(Node, ?MODULE, do, [Q]).
>
> That way the code would be executed on the remote
> node and the reply returned to your web code.
>


Actually - that was bad advice. The ?MODULE here
is the JIT compile .yaws file and that code will
not exist on the remote mnesia node. Better to
put that code in a separate module that can be loaded on
both nodes:

<erl>
....
do(Q) -> mymod:do(Q).

....

and then

-module(mymod).
....


do(Q) ->
         Node = figure_out_nodename(),
        rpc:call(Node, mymod, do, [Q]).

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list