Money.Ecto.Composite.Type (Money v1.11.0) View Source

Provides a type for Ecto to store a multi-currency price. The underlying data type should be an user-defined Postgres composite type :money_with_currency.

Migration

execute "CREATE TYPE public.money_with_currency AS (amount integer, currency varchar(3))"

create table(:my_table) do
  add :price, :money_with_currency
end

Schema

schema "my_table" do
  field :price, Money.Ecto.Composite.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

Specs

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

Callback implementation for Ecto.Type.cast/1.

Specs

dump(any()) :: :error | {:ok, {integer(), String.t()}}

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

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

Specs

load({integer(), atom() | String.t()}) :: {:ok, Money.t()}

Callback implementation for Ecto.Type.load/1.

Specs

type() :: :money_with_currency

Callback implementation for Ecto.Type.type/0.