mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 10:45:54 +00:00
25 lines
548 B
Elixir
25 lines
548 B
Elixir
defmodule WandererApp.Schema.AshErlangBinary do
|
|
use Ash.Type
|
|
|
|
@impl Ash.Type
|
|
def storage_type, do: :binary
|
|
|
|
@impl Ash.Type
|
|
def cast_input(value, _) do
|
|
{:ok, value}
|
|
end
|
|
|
|
@impl Ash.Type
|
|
def cast_stored(value, _) when not is_nil(value),
|
|
do: {:ok, :erlang.binary_to_term(value)}
|
|
|
|
@impl Ash.Type
|
|
def cast_stored(value, _), do: {:ok, value}
|
|
|
|
@impl Ash.Type
|
|
def dump_to_native(value, _) when not is_nil(value), do: {:ok, :erlang.term_to_binary(value)}
|
|
|
|
@impl Ash.Type
|
|
def dump_to_native(value, _), do: {:ok, value}
|
|
end
|