elixir-mongo / elixir-mongo/mongodb_ecto

Decimal Support [Or Custom Type Support Documentation]

Open
#149 3 comments 1 reaction 0 assignees View on GitHub
enhancement question
Dominant language
Elixir
Stars
378
Forks
127
PR merge metrics
No merged PRs in 30d

Description

Noticed that :decimal ecto native type is not supported but managed to get it working via a custom ecto type.

Where is the best place to include this? README or module docs?

```elixir
defmodule DecimalType do

@behaviour Ecto.Type
def type, do: :string

def cast(term) when is_binary(term) or is_number(term) do
{:ok, Decimal.new(term)}
end
def cast(_), do: :error

def dump(%Decimal{} = term) do
{:ok, Decimal.to_string(term)}
end
def dump(_), do: :error

def load(term) when is_binary(term) or is_number(term) do
{:ok, Decimal.new(term)}
end
def load(_), do: :error

end
````

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.