MishkaInstaller.Helper.MnesiaAssistant.Transaction (Mishka installer v0.1.8)

Copy Markdown View Source

Runs Mnesia activities and maps aborted results to the installer's error shape.

Summary

Functions

Runs fun as a fast, dirty ets activity. Delegates to :mnesia.ets/1.

Runs fun inside a Mnesia transaction. Delegates to :mnesia.transaction/1.

Builds a standard {:error, [map]} from an aborted transaction reason.

Functions

ets(fun)

@spec ets((-> any())) :: any()

Runs fun as a fast, dirty ets activity. Delegates to :mnesia.ets/1.

Only safe for ram_copies tables or read-only access on disc_copies.

transaction(fun)

@spec transaction((-> any())) :: {:atomic, any()} | {:aborted, term()}

Runs fun inside a Mnesia transaction. Delegates to :mnesia.transaction/1.

Returns {:atomic, result} or {:aborted, reason}.

transaction_error(reason, module, type, field, action)

@spec transaction_error(term(), module(), String.t(), atom(), atom()) ::
  {:error, [map()]}

Builds a standard {:error, [map]} from an aborted transaction reason.

The returned map carries :message, :field, :action and the raw :source error, so callers can surface a consistent error across the codebase.

Example

transaction_error(reason, MyTable, "reading", :global, :database)