View Source Money.Ecto.Amount.Type (Money v1.12.1)

Provides a type for Ecto to store a amount. The underlying data type should be an integer.

migration

Migration

create table(:my_table) do
  add :amount, :integer
end

schema

Schema

schema "my_table" do
  field :amount, Money.Ecto.Amount.Type
end

Link to this section Summary

Functions

Callback implementation for Ecto.Type.cast/1.

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Callback implementation for Ecto.Type.load/1.

Callback implementation for Ecto.Type.type/0.

Link to this section Functions

@spec cast(String.t() | integer() | Money.t() | map() | any()) ::
  {:ok, Money.t()} | :error

Callback implementation for Ecto.Type.cast/1.

@spec dump(integer() | Money.t()) :: {:ok, integer()}

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

@spec load(integer()) :: {:ok, Money.t()}

Callback implementation for Ecto.Type.load/1.

@spec type() :: :integer

Callback implementation for Ecto.Type.type/0.