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

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

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.

Functions

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

Callback implementation for Ecto.Type.cast/1.

@spec 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.

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

Callback implementation for Ecto.Type.load/1.

@spec type() :: :money_with_currency

Callback implementation for Ecto.Type.type/0.