View Source Memento.Query.Data (Memento v0.3.2)

Helper module that acts as an interface to convert Memento Table data structs into Mnesia data tuples and vice versa.

This is responsible for automatically handling conversions between data in methods defined in the Query module, so you won't need to use this at all.

usage

Usage

Given a Memento Table:

defmodule MyApp.User do
  use Memento.Table, attributes: [:id, :name]
end

You can convert its structs to Mnesia format:

Memento.Query.Data.dump(%MyApp.User{id: 1, name: "Sye"})
# => {MyApp.User, 1, "Sye"}

Or convert it back to a struct:

Memento.Query.Data.load({MyApp.User, 2, "Rick"})
# => %MyApp.User{id: 2, name: "Rick"}

Link to this section Summary

Functions

Convert Memento Table struct into Mnesia data tuple.

Convert Mnesia data tuple into Memento Table struct.

Link to this section Functions

Specs

Convert Memento Table struct into Mnesia data tuple.

Use this method when writing data to an Mnesia database. The argument should be a struct of a previously defined Memento table definition, and this will convert it into a tuple representing an Mnesia record.

Specs

Convert Mnesia data tuple into Memento Table struct.

Use this method when reading data from an Mnesia database. The data should be in a tuple format, where the first element is the Table name (Memento.Table definition).

This will automatically match the the tuple values against the table's attributes and convert it into a struct of the Memento table you defined.