mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
improvement: add cast_in_query?/0
to Ash.Type
This commit is contained in:
parent
223a71010a
commit
da04a883d9
1 changed files with 19 additions and 1 deletions
|
@ -103,6 +103,12 @@ defmodule Ash.Type do
|
|||
@type t :: atom | {:array, atom}
|
||||
|
||||
@callback storage_type() :: Ecto.Type.t()
|
||||
@doc """
|
||||
Useful for typed data layers (like ash_postgres) to instruct them not to attempt to cast input values.
|
||||
|
||||
You generally won't need this, but it can be an escape hatch for certain cases.
|
||||
"""
|
||||
@callback cast_in_query?() :: boolean
|
||||
@callback ecto_type() :: Ecto.Type.t()
|
||||
@callback cast_input(term, constraints) :: {:ok, term} | {:error, Keyword.t()} | :error
|
||||
@callback cast_input_array(list(term), constraints) ::
|
||||
|
@ -565,6 +571,14 @@ defmodule Ash.Type do
|
|||
end
|
||||
end
|
||||
|
||||
def cast_in_query?(type) do
|
||||
if ash_type?(type) do
|
||||
type.cast_in_query?()
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Casts a value from the Elixir type to a value that the data store can persist
|
||||
|
||||
|
@ -729,6 +743,9 @@ defmodule Ash.Type do
|
|||
@impl true
|
||||
def apply_constraints(_, _), do: :ok
|
||||
|
||||
@impl true
|
||||
def cast_in_query?, do: true
|
||||
|
||||
@impl true
|
||||
def handle_change(_old_value, new_value, _constraints), do: {:ok, new_value}
|
||||
|
||||
|
@ -745,7 +762,8 @@ defmodule Ash.Type do
|
|||
array_constraints: 0,
|
||||
apply_constraints: 2,
|
||||
handle_change: 3,
|
||||
prepare_change: 3
|
||||
prepare_change: 3,
|
||||
cast_in_query?: 0
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue