mnesia primary key creation

Matthew McDonnell matt@REDACTED
Fri Jun 30 10:13:33 CEST 2006


On Thu, 29 Jun 2006, Roberto Saccon wrote:

> I am wondering whether experienced erlang developers have something
> better in their best-practises-treasure-box than what I have come up
> with to create mnesia primary keys:

(not an experienced erlang developer)
I use a separate process to act as a server to access the database, with
the state of the server containing the last primary key used.  Something
like the following:

loop(Key) ->
  receive
    {From, {add, Record}} ->
      <mnesia transaction to insert {Key, Record}>
      loop(Key+1);
    ...

More robust solution is to do this in an OTP application with a gen_server
that can get restarted if it crashes, recalculates last Key when
intialised, is registered with a name eg mnesia_server, etc

Cheers,
	Matt

Matt McDonnell
Email: matt@REDACTED
Web:   http://www.matt-mcdonnell.com/



More information about the erlang-questions mailing list