A macro module and behaviour with default mapping implementations.
The docs can be found at https://hexdocs.pm/data_mapper.
The package can be installed by adding data_mapper
to your list of dependencies in mix.exs
:
def deps do
[
{:data_mapper, "~> 0.1.0"}
]
end
defmodule FooMapper do
@moduledoc """
Map the Foo external data to our own data structures.
"""
use DataMapper,
mappings: %{
"someFoo" => :foo,
"someBar" => :bar,
"extraThing" => :extra_thing
}
@impl DataMapper
def map_field({_, nil} = field), do: field
def map_field({:bar, field}) do
{:bar, field * 1000}
end
def map_field(field), do: field
end