Money v1.2.0 Money.Ecto.Map.Type View Source
Implements Ecto.Type behaviour for Money, where the underlying schema type is a map.
This is the required option for databases such as MySQL that do not support composite types.
In order to preserve precision, the amount is serialized as a string since the JSON representation of a numeric value is either an integer or a float.
Decimal.to_string/1
is not guaranteed to produce a string that will round-trip
convert back to the identical number. However given enough precision in the
Decimal.get_context/0
then round trip conversion should be expected. The default
precision in the context is 28 digits.
Link to this section Summary
Functions
Casts the given input to the custom type.
Dumps the given term into an Ecto native type.
Dictates how the type should be treated inside embeds.
Checks if two terms are semantically equal.
Loads the given term into a custom type.
Returns the underlying schema type for the custom type.
Link to this section Functions
Casts the given input to the custom type.
This callback is called on external input and can return any type,
as long as the dump/1
function is able to convert the returned
value into an Ecto native type. There are two situations where
this callback is called:
- When casting values by
Ecto.Changeset
- When passing arguments to
Ecto.Query
When returning {:error, keyword()}
, the returned keyword list
will be preserved in the changeset errors, similar to
Changeset.add_error/4
. Passing a :message
key, will override
the default message. It is not possible to override the :type
key.
For {:array, CustomType}
or {:map, CustomType}
the returned
keyword list will be erased and the default error will be shown.
Callback implementation for Ecto.Type.cast/1
.
Dumps the given term into an Ecto native type.
This callback is called with any term that was stored in the struct and it needs to validate them and convert it to an Ecto native type.
Callback implementation for Ecto.Type.dump/1
.
Dictates how the type should be treated inside embeds.
By default, the type is sent as itself, without calling
dumping to keep the higher level representation. But
it can be set to :dump
to it is dumped before encoded.
Callback implementation for Ecto.Type.embed_as/1
.
Checks if two terms are semantically equal.
Callback implementation for Ecto.Type.equal?/2
.
Loads the given term into a custom type.
This callback is called when loading data from the database and
receives an Ecto native type. It can return any type, as long as
the dump/1
function is able to convert the returned value back
into an Ecto native type.
Callback implementation for Ecto.Type.load/1
.
Returns the underlying schema type for the custom type.
For example, if you want to provide your own date
structures, the type function should return :date
.
Note this function is not required to return Ecto primitive types, the type is only required to be known by the adapter.
Callback implementation for Ecto.Type.type/0
.