How to detect whether the mnesia schema and table have been created in code?

StackOverflow https://stackoverflow.com/questions/9186848

  •  27-04-2021
  •  | 
  •  

Domanda

I want to create an mnesia schema and table in my code after the system starts, so I need to detect weather the mnesia schema and table have been created. If not, I want to create them. Is this a good idea? And how can I detect the mnesia schema and table?

È stato utile?

Soluzione

One way to handle this is -

  1. Try creating table using mnesia:create_table(Table_name, ...)

  2. If the table already exists (1) would return {aborted, {already_exists, Table_name}}

  3. If table doesn't exit, it will be created and {atomic,ok} will be returned if successful

  4. If there is any error in table creation in (3), {aborted, Reason} will be returned.

Handle each of these return values as required.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top