plug_session_mnesia v0.1.2 PlugSessionMnesia.Helpers View Source

Helpers for creating the Mnesia table.

You can use the functions in this module to create the Mnesia table used by PlugSessionMnesia.Store 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 sessions from the table

Clears all sessions 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 the session storage

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

Link to this section Functions

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

Clears all sessions from the table.

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

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

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

config :plug_session_mnesia,
  table: :session,
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 :plug_session_mnesia,
  table: :session,
Link to this function setup(table, persistent? \\ :persistent) View Source
setup(atom(), :persistent | :volatile) ::
  :ok |
  {:error | :abort, term()}

Creates a Mnesia table for the session 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 session 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> PlugSessionMnesia.Helpers.setup(:session)
:ok
iex> :mnesia.create_table(:test, [attributes: [:id, :data]])
{:atomic, :ok}
iex> PlugSessionMnesia.Helpers.setup(:test)
{:error, already_exists}
Link to this function setup!() View Source
setup!() :: :ok

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

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

config :plug_session_mnesia,
  table: :session,

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

If the table already exists with different attributes, a PlugSessionMnesia.TableExists is raised.