View Source Memento.Query.Data (memento v0.4.1)
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
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"}
Summary
Functions
Convert Memento Table struct into Mnesia data tuple.
Convert Mnesia data tuple into Memento Table struct.
Functions
@spec dump(Memento.Table.record()) :: tuple()
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.
@spec load(tuple()) :: Memento.Table.record()
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.