mnesia query for list membership?

Bjorn Turesson btu@REDACTED
Wed Dec 16 17:56:14 CET 1998


On Wed, 16 Dec 1998, Edwin Young wrote:

> Hello,
> 
> I tried the following, but I got an impenetrable error message (which I
> don't have with me: sorry).
> Any suggestions?
> 
> -record(document, {id
>             title}).

You do have a comma between id and title, don't you?

I tried your code (exact example attached) and it works
like a charm on the version I got here (which is very similar 
to the open source that is released).

The shell output is as follows:

Erlang (JAM) emulator version 4.7.3.4
 
Eshell V4.7.3.4  (abort with ^G)
1> c(tst).
{ok,tst}
2> tst:s().
{atomic,ok}
3> tst:add(23,hello).
{atomic,ok}
4> tst:docs(2).
{atomic,[hello]}


			// bjoern


--
Mouse moved last hour: 41.84, today: 364.28, this week: 627.84 (meters)
-------------- next part --------------
-module(tst).

-compile(export_all).
-compile({parse_transform,mnemosyne}).

-record(document, {id,
		   title}).

-export ([s/0, add/2,
	  docs/1]).

s () ->
    mnesia:start (),
    application:start(mnemosyne),
    mnesia:create_table (document, 
		 [{attributes, record_info(fields, document)}]).

add (Id, Title) ->
    Fun = fun () ->
		  mnesia:write (#document{id=Id, title=Title})
	  end,
    mnesia:transaction (Fun).


docs(Term) ->
    Fun = fun() ->
		  Q = query [ D.title || D <- table(document),
					 lists:member(1,[1]) ]
		      end,
		  mnemosyne:eval(Q)
	  end,
    mnesia:transaction(Fun).




More information about the erlang-questions mailing list