-
-
Notifications
You must be signed in to change notification settings - Fork 117
refactor: move immutable error expressions from AshSql into AshPostgres #633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: move immutable error expressions from AshSql into AshPostgres #633
Conversation
if Ash.Expr.expr?(input) do | ||
frag_parts = | ||
Enum.flat_map(input, fn {key, value} -> | ||
if Ash.Expr.expr?(value) do | ||
[ | ||
expr: to_string(key), | ||
raw: "::text, ", | ||
expr: value, | ||
raw: ", " | ||
] | ||
else | ||
[ | ||
expr: to_string(key), | ||
raw: "::text, ", | ||
expr: value, | ||
raw: "::jsonb, " | ||
] | ||
end | ||
end) | ||
|
||
frag_parts = | ||
List.update_at(frag_parts, -1, fn {:raw, text} -> | ||
{:raw, String.trim_trailing(text, ", ") <> "))"} | ||
end) | ||
|
||
AshSql.Expr.dynamic_expr( | ||
query, | ||
%Ash.Query.Function.Fragment{ | ||
embedded?: false, | ||
arguments: | ||
[ | ||
raw: "jsonb_build_object('exception', ", | ||
expr: inspect(exception), | ||
raw: "::text, 'input', jsonb_build_object(" | ||
] ++ | ||
frag_parts | ||
}, | ||
bindings, | ||
embedded?, | ||
nil, | ||
acc | ||
) | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit has a bit of duplication with AshSql for now, but some of this will be reworked soon specifically for immutable raise errors so it's good that it's separate
end | ||
|
||
# Returns a row-dependent token to prevent constant-folding for immutable functions. | ||
defp immutable_error_expr_token(query, bindings) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is moved from AshSql, will revert the code I added there last week
[ | ||
{:ash, ash_version("~> 3.5 and >= 3.5.35")}, | ||
{:spark, "~> 2.3 and >= 2.3.4"}, | ||
# TODO: bump to next ash_sql release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this in the previous PR, and since the immutable error expressions are self-contained within AshPostgres now, there's no hard requirement to bump the AshSql version for this
Though you may still want to for that other typing bugfix
🚀 Thank you for your contribution! 🚀 |
Instead of splitting the code across AshPostgres and AshSql for this, I realized that we can keep it entirely self-contained in AshPostgres using AshSql's
expr
callback.Contributor checklist
Leave anything that you believe does not apply unchecked.