Skip to content

Commit

Permalink
fix: make tests that use JSON_EXTRACT() internally pass
Browse files Browse the repository at this point in the history
  • Loading branch information
lejoko committed May 21, 2024
1 parent e99e902 commit d085025
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions lib/sql_implementation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -349,44 +349,32 @@ defmodule AshMysql.SqlImplementation do
bindings,
embedded?,
acc,
type \\ nil
_type \\ nil
) do
path = "$." <> Enum.join(right, ".")
field = Ash.Query.Ref.name(left)
path = Enum.map(right, &to_string/1)

expr =
Ecto.Query.dynamic([row], json_extract_path(field(row, ^field), ^path))

{expr, acc} =
AshSql.Expr.dynamic_expr(
query,
%Ash.Query.Function.Fragment{
embedded?: pred_embedded?,
arguments: [
raw: "json_extract(",
expr: left,
raw: ", ",
expr: path,
raw: "json_unquote(",
expr: expr,
raw: ")"
]
},
bindings,
embedded?,
type,
Ash.Type.String,
acc
)

if type do
{expr, acc} =
AshSql.Expr.dynamic_expr(
query,
%Ash.Query.Function.Type{arguments: [expr, type, []]},
bindings,
embedded?,
type,
acc
)

{:ok, expr, acc}
else
{:ok, expr, acc}
end
{:ok, expr, acc}
end

defp determine_type_at_path(type, path) do
Expand Down

0 comments on commit d085025

Please sign in to comment.