From 5dbeb57991951554a3106a72af3700048c21c965 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Mon, 2 Dec 2024 19:54:31 -0500 Subject: [PATCH] improvement: update sql implementation for type determination --- lib/sql_implementation.ex | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/sql_implementation.ex b/lib/sql_implementation.ex index ae4f863d..dc65ec91 100644 --- a/lib/sql_implementation.ex +++ b/lib/sql_implementation.ex @@ -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 @@ -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