Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

## Unreleased

- Allow overriding the global `default_limit` by setting `default_limit: false` in the schema
### Changed

- Allow overriding the global `default_limit` by setting `default_limit: false`
in the schema.

## Fixed
### Fixed

- Remove malformed filters if `replace_invalid_params` is `true` (e.g. if the
parameters include `%{"filters" => ""}` instead of a filters list.
- Fix redundant function clause warnings in Elixir 1.20.

## [0.26.3] - 2025-05-29

Expand Down
File renamed without changes.
44 changes: 23 additions & 21 deletions lib/flop/adapter/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -889,28 +889,30 @@ defmodule Flop.Adapter.Ecto do
build_dynamic(unquote(fragment), false, unquote(combinator))
end

defp build_op(
_schema_struct,
%FieldInfo{
extra: %{type: :custom, field_dynamic: {mod, fun, dynamic_opts}}
},
%Filter{op: unquote(op), value: value},
extra_opts
) do
unquote(prelude)
dynamic_opts = Keyword.merge(extra_opts, dynamic_opts)
field_dynamic = apply(mod, fun, [dynamic_opts])
build_dynamic(unquote(fragment_dynamic), false, unquote(combinator))
end
if op not in [:empty, :not_empty] do
defp build_op(
_schema_struct,
%FieldInfo{
extra: %{type: :custom, field_dynamic: {mod, fun, dynamic_opts}}
},
%Filter{op: unquote(op), value: value},
extra_opts
) do
unquote(prelude)
dynamic_opts = Keyword.merge(extra_opts, dynamic_opts)
field_dynamic = apply(mod, fun, [dynamic_opts])
build_dynamic(unquote(fragment_dynamic), false, unquote(combinator))
end

defp build_op(
_schema_struct,
%FieldInfo{extra: %{type: :join, binding: binding, field: field}},
%Filter{op: unquote(op), value: value},
_extra_opts
) do
unquote(prelude)
build_dynamic(unquote(fragment), true, unquote(combinator))
defp build_op(
_schema_struct,
%FieldInfo{extra: %{type: :join, binding: binding, field: field}},
%Filter{op: unquote(op), value: value},
_extra_opts
) do
unquote(prelude)
build_dynamic(unquote(fragment), true, unquote(combinator))
end
end
end

Expand Down
5 changes: 3 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Flop.MixProject do
deps: deps(),
test_coverage: [tool: ExCoveralls],
test_paths: test_paths(System.get_env("ECTO_ADAPTER")),
test_ignore_filters: [&String.ends_with?(&1, "migration.exs")],
dialyzer: [
ignore_warnings: ".dialyzer_ignore.exs",
list_unused_filters: true,
Expand Down Expand Up @@ -74,11 +75,11 @@ defmodule Flop.MixProject do
{:ex_machina, "2.8.0", only: :test},
{:makeup_diff, "0.1.1", only: :dev, runtime: false},
{:excoveralls, "0.18.5", only: :test},
{:myxql, "0.8.0", only: :test},
{:myxql, "0.8.1", only: :test},
{:nimble_options, "~> 1.0"},
{:postgrex, "0.22.0", only: :test},
{:ecto_sqlite3, "0.22.0", only: :test},
{:stream_data, "1.2.0", only: [:dev, :test]}
{:stream_data, "1.3.0", only: [:dev, :test]}
]
end

Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"makeup_diff": {:hex, :makeup_diff, "0.1.1", "01498f8c95970081297837eaf4686b6f3813e535795b8421f15ace17a59aea37", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "fadb0bf014bd328badb7be986eadbce1a29955dd51c27a9e401c3045cf24184e"},
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.3", "4252d5d4098da7415c390e847c814bad3764c94a814a0b4245176215615e1035", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "953297c02582a33411ac6208f2c6e55f0e870df7f80da724ed613f10e6706afd"},
"myxql": {:hex, :myxql, "0.8.0", "60c60e87c7320d2f5759416aa1758c8e7534efbae07b192861977f8455e35acd", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:geo, "~> 3.4 or ~> 4.0", [hex: :geo, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "1ec0ceb26fb3cd0f8756519cf4f0e4f9348177a020705223bdf4742a2c44d774"},
"myxql": {:hex, :myxql, "0.8.1", "5d7b96f288a98927a40309b274917d16a288a8c0b273205135913ff9799563b3", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:geo, "~> 3.4 or ~> 4.0", [hex: :geo, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "85a4795712bbab1a0f0803d5f0c7332bb383e5f07d3443a42e17a9aa996bbddb"},
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
"postgrex": {:hex, :postgrex, "0.22.0", "fb027b58b6eab1f6de5396a2abcdaaeb168f9ed4eccbb594e6ac393b02078cbd", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "a68c4261e299597909e03e6f8ff5a13876f5caadaddd0d23af0d0a61afcc5d84"},
"stream_data": {:hex, :stream_data, "1.2.0", "58dd3f9e88afe27dc38bef26fce0c84a9e7a96772b2925c7b32cd2435697a52b", [:mix], [], "hexpm", "eb5c546ee3466920314643edf68943a5b14b32d1da9fe01698dc92b73f89a9ed"},
"telemetry": {:hex, :telemetry, "1.4.0", "69aa83d53f152f93f05fd40b77ded6fab247de093b7a3c4ca2879e634144446e", [:rebar3], [], "hexpm", "d1ff426f988ac1092f9d684d34d08e51042a70567c16be793fbc8f399fd2e77d"},
"stream_data": {:hex, :stream_data, "1.3.0", "bde37905530aff386dea1ddd86ecbf00e6642dc074ceffc10b7d4e41dfd6aac9", [:mix], [], "hexpm", "3cc552e286e817dca43c98044c706eec9318083a1480c52ae2688b08e2936e3c"},
"telemetry": {:hex, :telemetry, "1.4.1", "ab6de178e2b29b58e8256b92b382ea3f590a47152ca3651ea857a6cae05ac423", [:rebar3], [], "hexpm", "2172e05a27531d3d31dd9782841065c50dd5c3c7699d95266b2edd54c2dafa1c"},
}
13 changes: 2 additions & 11 deletions test/support/test_util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,11 @@ defmodule Flop.TestUtil do
default_limit: 999_999_999
)

sort? = opts[:sort] || true

q =
Pet
|> join(:left, [p], o in assoc(p, :owner), as: :owner)
|> preload(:owner)

q = if sort?, do: order_by(q, [p], p.id), else: q
|> order_by([p], p.id)

opts = opts |> Keyword.take([:extra_opts]) |> Keyword.put(:for, Pet)

Expand All @@ -342,13 +339,7 @@ defmodule Flop.TestUtil do
default_limit: 999_999_999
]

sort? = opts[:sort] || true

params =
if sort?,
do: Map.merge(params, %{order_by: [:id], order_directions: [:asc]}),
else: params

params = Map.merge(params, %{order_by: [:id], order_directions: [:asc]})
flop = Flop.validate!(params, flop_opts)

q =
Expand Down
Loading