MishkaInstaller.Helper.MnesiaAssistant (Mishka installer v0.1.7)

Copy Markdown View Source

A focused Elixir wrapper around the Erlang :mnesia runtime database used by MishkaInstaller.

It exposes only what the installer needs and standardises a few outputs. The full API is split into:

Summary

Functions

Connects this (running, empty-schema) node to the cluster nodes. Delegates to :mnesia.change_config/2. Returns {:ok, connected_nodes} or {:error, reason}.

Translates a result selector into the Erlang match-spec result body. See MishkaInstaller.Helper.Extra.erlang_result/1.

Builds the head tuple of an Erlang match specification. See MishkaInstaller.Helper.Extra.erlang_fields/4.

Starts the Mnesia application. Delegates to :mnesia.start/0.

Stops the Mnesia application. Delegates to :mnesia.stop/0.

Subscribes the calling process to Mnesia what events (e.g. :system). Delegates to :mnesia.subscribe/1.

Converts Mnesia record tuples into maps or structs.

Unsubscribes from Mnesia what events. Delegates to :mnesia.unsubscribe/1.

Functions

change_config(nodes)

@spec change_config([node()]) :: {:ok, [node()]} | {:error, term()}

Connects this (running, empty-schema) node to the cluster nodes. Delegates to :mnesia.change_config/2. Returns {:ok, connected_nodes} or {:error, reason}.

er(operation)

Translates a result selector into the Erlang match-spec result body. See MishkaInstaller.Helper.Extra.erlang_result/1.

erl_fields(tuple, fields, keys, num)

Builds the head tuple of an Erlang match specification. See MishkaInstaller.Helper.Extra.erlang_fields/4.

start()

@spec start() :: :ok | {:error, term()}

Starts the Mnesia application. Delegates to :mnesia.start/0.

stop()

@spec stop() :: :stopped | {:error, term()}

Stops the Mnesia application. Delegates to :mnesia.stop/0.

subscribe(what)

@spec subscribe(term()) :: {:ok, node()} | {:error, term()}

Subscribes the calling process to Mnesia what events (e.g. :system). Delegates to :mnesia.subscribe/1.

tuple_to_map(records, fields, struct, drop)

@spec tuple_to_map(list() | tuple() | :"$end_of_table", [atom()], module() | nil, [
  atom()
]) ::
  list() | {list(), any()}

Converts Mnesia record tuples into maps or structs.

  • :"$end_of_table" becomes [].
  • {records, cont} (a paginated select result) keeps the continuation: {converted, cont}.
  • a list of record tuples becomes a list; each tuple is zipped with fields (the leading record tag is dropped), drop keys are removed, and — when struct is not nil — wrapped with struct!/2.

Examples

iex> MishkaInstaller.Helper.MnesiaAssistant.tuple_to_map([{Person, 1, "a"}], [:id, :name], nil, [])
[%{id: 1, name: "a"}]

unsubscribe(what)

@spec unsubscribe(term()) :: {:ok, node()} | {:error, term()}

Unsubscribes from Mnesia what events. Delegates to :mnesia.unsubscribe/1.