expected v0.1.1 Expected.MnesiaStore.Helpers View Source

Helpers for creating the Mnesia table.

You can use the functions in this module to create the Mnesia table used by Expected.MnesiaStore on the current node. If you want more advanced features like distribution, you should create the table yourself.

Link to this section Summary

Functions

Clears all logins from the table

Clears all logins from the Mnesia table given in the configuration

Drops the Mnesia table

Drops the Mnesia table given in the configuration

Creates a Mnesia table for login storage

Sets up the Mnesia table for login storage according to the configuration

Link to this section Functions

Link to this function clear(table) View Source
clear(atom()) :: :ok

Clears all logins from the table.

Link to this function clear!() View Source
clear!() :: :ok

Clears all logins from the Mnesia table given in the configuration.

For this function to work, :table must be set in your config.exs:

config :expected,
  store: :mnesia,
  table: :logins,
  ...
Link to this function drop(table) View Source
drop(atom()) :: :ok

Drops the Mnesia table.

Drops the Mnesia table given in the configuration.

For this function to work, :table must be set in your config.exs:

config :expected,
  store: :mnesia,
  table: :logins,
  ...
Link to this function setup(table, persistent? \\ :persistent) View Source
setup(atom(), :persistent | :volatile) :: return_value()

Creates a Mnesia table for login storage.

Parameters

  • table - Mnesia table name
  • persistent? - persistence mode. :persistent automatically sets the schema and the table to keep a copy of their data in both RAM and disk. :volatile lets the schema copy mode untouched and creates a RAM-only login store.

Return values

  • :ok - the table has been successfully created
  • {:error, :already_exists} - a table with the same name but different attribute already exists. If the table has the correct attributes, there is no error.
  • Any other error from Mnesia

Examples

iex> Expected.MnesiaStore.Helpers.setup(:logins)
:ok
iex> :mnesia.create_table(:test, [attributes: [:id, :data]])
{:atomic, :ok}
iex> Expected.MnesiaStore.Helpers.setup(:test)
{:error, already_exists}
Link to this function setup!() View Source
setup!() :: :ok

Sets up the Mnesia table for login storage according to the configuration.

For this function to work, :table must be set in your config.exs:

config :expected,
  store: :mnesia,
  table: :logins,
  ...

It then creates a Mnesia table with copies in RAM and on disk, so that logins are persistent accross application reboots. For more information about the process, see setup/2.

If the table already exists with different attributes, an Expected.MnesiaTableExistsError is raised.