Skip to content

Commit

Permalink
improvement: update sql implementation for type determination
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 3, 2024
1 parent d6bb54a commit 5dbeb57
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions lib/sql_implementation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ defmodule AshPostgres.SqlImplementation do
end
end

def parameterized_type({type, constraints}, [], no_maps?) do
parameterized_type(type, constraints, no_maps?)
end

def parameterized_type(Ash.Type.CiString, constraints, no_maps?) do
parameterized_type(AshPostgres.Type.CiStringWrapper, constraints, no_maps?)
end
Expand Down Expand Up @@ -279,28 +283,23 @@ defmodule AshPostgres.SqlImplementation do

@impl true
def determine_types(mod, args, returns \\ nil) do
{types, new_returns} = Ash.Expr.determine_types(mod, args, returns)
case returns do
{:parameterized, _} -> raise "what"
_ -> :ok
end

new_returns =
case new_returns do
{:parameterized, _} = parameterized -> parameterized
{:array, _} = type -> parameterized_type(type, [])
{type, constraints} -> parameterized_type(type, constraints)
returns =
case returns do
{:parameterized, _} -> nil
{:array, {:parameterized, _}} -> nil
{:array, {type, constraints}} when type != :array -> {type, [items: constraints]}
{:array, _} -> nil
{type, constraints} -> {type, constraints}
other -> other
end

{Enum.map(types, fn
{:parameterized, _} = parameterized ->
parameterized

{:array, _} = type ->
parameterized_type(type, [])

{type, constraints} ->
parameterized_type(type, constraints)
{types, new_returns} = Ash.Expr.determine_types(mod, args, returns)

other ->
other
end), new_returns || returns}
{types, new_returns || returns}
end
end

0 comments on commit 5dbeb57

Please sign in to comment.