• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nshkrdotcom / ElixirScope / c7479091597c3382f92c87a4fd0395db3ee30193

30 May 2025 03:48PM UTC coverage: 57.42% (-0.3%) from 57.672%
c7479091597c3382f92c87a4fd0395db3ee30193

push

github

NSHkr
refactor expression_processors

98 of 221 new or added lines in 6 files covered. (44.34%)

28 existing lines in 2 files now uncovered.

6210 of 10815 relevant lines covered (57.42%)

3137.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

31.25
/lib/elixir_scope/ast_repository/query_builder/normalizer.ex
1
defmodule ElixirScope.ASTRepository.QueryBuilder.Normalizer do
2
  @moduledoc """
3
  Normalizes query specifications into consistent internal format.
4
  """
5

6
  alias ElixirScope.ASTRepository.QueryBuilder.Types
7

8
  @doc """
9
  Normalizes a query specification from various input formats into a Types struct.
10
  """
11
  @spec normalize_query(map() | Types.query_t()) :: {:ok, Types.query_t()} | {:error, term()}
12
  def normalize_query(query_spec) when is_map(query_spec) do
13
    query = %Types{
30✔
14
      select: Map.get(query_spec, :select, :all),
15
      from: Map.get(query_spec, :from, :functions),
16
      where: Map.get(query_spec, :where, []),
17
      order_by: normalize_order_by(Map.get(query_spec, :order_by)),
18
      limit: Map.get(query_spec, :limit),
19
      offset: Map.get(query_spec, :offset, 0),
20
      group_by: Map.get(query_spec, :group_by),
21
      having: Map.get(query_spec, :having),
22
      joins: Map.get(query_spec, :joins)
23
    }
24

25
    {:ok, query}
26
  end
27

28
  def normalize_query(%Types{} = query), do: {:ok, query}
×
UNCOV
29
  def normalize_query(_), do: {:error, :invalid_query_format}
×
30

31
  @doc """
32
  Normalizes ORDER BY specifications into consistent format.
33
  """
34
  @spec normalize_order_by(term()) :: term()
35
  def normalize_order_by(nil), do: nil
22✔
36

37
  def normalize_order_by(order_by) when is_list(order_by) do
38
    Enum.map(order_by, fn
2✔
39
      {field, direction} -> {field, direction}
5✔
40
      other -> other
×
41
    end)
42
  end
43

44
  def normalize_order_by(order_by), do: order_by
6✔
45

46
  @doc """
47
  Normalizes WHERE conditions to ensure consistent format.
48
  """
49
  @spec normalize_where_conditions(list()) :: list()
50
  def normalize_where_conditions(conditions) when is_list(conditions) do
51
    Enum.map(conditions, &normalize_condition/1)
×
52
  end
53

54
  def normalize_where_conditions(conditions), do: conditions
×
55

56
  # Private helper functions
57

58
  defp normalize_condition({field, op, value}) when is_atom(field) and is_atom(op) do
59
    {field, op, value}
×
60
  end
61

62
  defp normalize_condition({field, op}) when is_atom(field) and op in [:not_nil, :nil] do
×
63
    {field, op}
64
  end
65

66
  defp normalize_condition({:and, conditions}) when is_list(conditions) do
×
67
    {:and, Enum.map(conditions, &normalize_condition/1)}
68
  end
69

70
  defp normalize_condition({:or, conditions}) when is_list(conditions) do
×
71
    {:or, Enum.map(conditions, &normalize_condition/1)}
72
  end
73

74
  defp normalize_condition({:not, condition}) do
×
75
    {:not, normalize_condition(condition)}
76
  end
77

78
  defp normalize_condition(condition), do: condition
×
79
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc