-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the dynamic assumption of table field (#8)
* Remove the dynamic assumption of table field - Adds field_or_alias concept to ordering and page break that holds the previously held assumption of table column in as expr in the structs - Utilizes the field_or_alias for the Fob apply_keyset_comparison dynamics * Keep all changes internal for Haste * Changelog for the feature. - Assuming we want a minor bump for new functionality? But perhaps we call this a patch as all the changes are internal * Coverage for fragment builder
- Loading branch information
1 parent
3bb172a
commit a6ef115
Showing
7 changed files
with
256 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
defmodule Fob.FragmentBuilder do | ||
@moduledoc false | ||
@spec build([Macro.t()], Macro.t(), Macro.t(), Macro.Env.t()) :: Macro.t() | ||
def build(binding, expr, params, env) do | ||
quote do | ||
%Ecto.Query.DynamicExpr{ | ||
fun: fn query -> | ||
{unquote(expr), unquote(params), []} | ||
end, | ||
binding: unquote(Macro.escape(binding)), | ||
file: unquote(env.file), | ||
line: unquote(env.line) | ||
} | ||
end | ||
end | ||
|
||
defmacro build_from_existing(binding \\ [], expr) do | ||
build(binding, expr, [], __CALLER__) | ||
end | ||
|
||
def table_for_fragment({:fragment, [], _} = frag) do | ||
Macro.prewalk(frag, nil, fn ast, acc -> | ||
case ast do | ||
{:&, [], [table_idx]} when is_integer(table_idx) -> | ||
{ast, table_idx} | ||
|
||
_ -> | ||
{ast, acc} | ||
end | ||
end) | ||
|> elem(1) | ||
end | ||
|
||
def column_for_query_fragment( | ||
{:fragment, [], _} = frag, | ||
%Ecto.Query{} = query | ||
) do | ||
query.select.expr | ||
|> Macro.prewalk(nil, fn ast, acc -> | ||
case ast do | ||
{virtual_column, ^frag} when is_atom(virtual_column) -> | ||
{ast, virtual_column} | ||
|
||
_ -> | ||
{ast, acc} | ||
end | ||
end) | ||
|> elem(1) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.