ecto_mnesia v0.9.1 EctoMnesia.Planner

Core Ecto Mnesia adapter implementation.

Link to this section Summary

Functions

Automatically generate next ID for binary keys, leave sequence keys empty for generation on insert

Returns the childspec that starts the adapter process. This method is called from Ecto.Repo.Supervisor.init/2

Deletes a record from a Mnesia database

Returns the dumpers for a given type

Ensure all applications necessary to run the adapter are started

Update all records by a Ecto.Query

Returns true when called inside a transaction

Insert Ecto Schema struct to Mnesia database

Returns the loaders for a given type

Prepares are called by Ecto before execute/6 methods

Transaction rollbacks is not fully supported

Run fun inside a Mnesia transaction

Updates record stored in a Mnesia database

Link to this section Functions

Link to this function autogenerate(atom)

Automatically generate next ID for binary keys, leave sequence keys empty for generation on insert.

Link to this function child_spec(repo, opts)

Returns the childspec that starts the adapter process. This method is called from Ecto.Repo.Supervisor.init/2.

Link to this function delete(repo, map, filter, opts)

Deletes a record from a Mnesia database.

Link to this function dumpers(primitive, type)

Returns the dumpers for a given type.

It receives the primitive type and the Ecto type (which may be primitive as well). It returns a list of dumpers with the given type usually at the beginning.

This allows developers to properly translate values coming from the Ecto into adapter ones. For example, if the database does not support booleans but instead returns 0 and 1 for them, you could add:

def dumpers(:boolean, type), do: [type, &bool_encode/1]
def dumpers(_primitive, type), do: [type]

defp bool_encode(false), do: {:ok, 0}
defp bool_encode(true), do: {:ok, 1}

All adapters are required to implement a clause or :binary_id types, since they are adapter specific. If your adapter does not provide binary ids, you may simply use Ecto.UUID:

def dumpers(:binary_id, type), do: [type, Ecto.UUID]
def dumpers(_primitive, type), do: [type]

Callback implementation for Ecto.Adapter.dumpers/2.

Link to this function ensure_all_started(repo, type)

Ensure all applications necessary to run the adapter are started.

Link to this function execute(repo, map, arg, sources, preprocess, opts)

Update all records by a Ecto.Query.

Link to this function in_transaction?(repo)

Returns true when called inside a transaction.

Link to this function insert(repo, map, sources, on_conflict, returning, opts)

Insert Ecto Schema struct to Mnesia database.

Link to this function insert_all(repo, map, header, rows, on_conflict, returning, opts)

Insert all

Link to this function loaders(primitive, type)

Returns the loaders for a given type.

It receives the primitive type and the Ecto type (which may be primitive as well). It returns a list of loaders with the given type usually at the end.

This allows developers to properly translate values coming from the adapters into Ecto ones. For example, if the database does not support booleans but instead returns 0 and 1 for them, you could add:

def loaders(:boolean, type), do: [&bool_decode/1, type]
def loaders(_primitive, type), do: [type]

defp bool_decode(0), do: {:ok, false}
defp bool_decode(1), do: {:ok, true}

All adapters are required to implement a clause for :binary_id types, since they are adapter specific. If your adapter does not provide binary ids, you may simply use Ecto.UUID:

def loaders(:binary_id, type), do: [Ecto.UUID, type]
def loaders(_primitive, type), do: [type]

Callback implementation for Ecto.Adapter.loaders/2.

Link to this function prepare(operation, query)

Prepares are called by Ecto before execute/6 methods.

Link to this function rollback(repo, tid)

Transaction rollbacks is not fully supported.

Link to this function transaction(repo, opts, fun)

Run fun inside a Mnesia transaction

Link to this function update(repo, map, params, filter, autogen, opts)

Updates record stored in a Mnesia database.