valyukov / ex_sieve Goto Github PK
View Code? Open in Web Editor NEWImplement dynamic filtering and sorting API for Ecto queries
License: MIT License
Implement dynamic filtering and sorting API for Ecto queries
License: MIT License
I am trying to filter some results by ìnserted_at
date but I am getting this error:
(Ecto.Query.CastError) deps/ex_sieve/lib/ex_sieve/builder/where.ex:13: value
"2017-10-10"in
where cannot be cast to type :naive_datetime in query:
This library is interesting and much less verbose to use than others, I hope development continues :)
Work in progress, right now Repo.filter() chokes on plain queries, because aliases might be already defined.
Quick and dirty changes I made to make this work:
12:30 $ git diff
diff --git a/lib/ex_sieve.ex b/lib/ex_sieve.ex
index 70318ae..05a4365 100644
--- a/lib/ex_sieve.ex
+++ b/lib/ex_sieve.ex
@@ -47,6 +47,6 @@ defmodule ExSieve do
defp result({:error, reason}, _queryable), do: {:error, reason}
defp result({:ok, groupings, sorts}, queryable), do: Builder.call(queryable, groupings, sorts)
- defp extract_schema(%{from: {_, schema}}), do: schema
+ defp extract_schema(%{from: %{source: {_, schema}}}), do: schema
defp extract_schema(schema), do: schema
end
diff --git a/lib/ex_sieve/builder/join.ex b/lib/ex_sieve/builder/join.ex
index bcc48bc..1b27fde 100644
--- a/lib/ex_sieve/builder/join.ex
+++ b/lib/ex_sieve/builder/join.ex
@@ -61,12 +61,17 @@ defmodule ExSieve.Builder.Join do
end
defp apply_join({parent, relation} = pr, query) do
- query
- |> Macro.escape()
- |> Join.build(:inner, join_binding(parent), expr(relation), nil, nil, join_as(pr), nil, nil, __ENV__)
- |> elem(0)
- |> Code.eval_quoted()
- |> elem(0)
+ cond do
+ Map.has_key?(query.aliases, relation) ->
+ query
+ true ->
+ query
+ |> Macro.escape()
+ |> Join.build(:inner, join_binding(parent), expr(relation), nil, nil, join_as(pr), nil, nil, __ENV__)
+ |> elem(0)
+ |> Code.eval_quoted()
+ |> elem(0)
+ end
end
The main changes:
In ecto 2.0
@SPEC escape_binding(list) :: Keyword.t
def escape_binding(binding) when is_list(binding) do
changed to
In ecto 2.1.3
@SPEC escape_binding(Macro.t | Ecto.Query.t, list) :: {Macro.t | Ecto.Query.t, Keyword.t}
def escape_binding(query, binding) when is_list(binding) do
In ecto 2.0
@SPEC build(:where | :having, Macro.t, [Macro.t], Macro.t, Macro.Env.t) :: Macro.t
def build(kind, query, _binding, {:^, _, [var]}, env) do
changed to
in ecto 2.1.3
@SPEC build(:where | :having, :and | :or, Macro.t, [Macro.t], Macro.t, Macro.Env.t) :: Macro.t
def build(kind, op, query, _binding, {:^, _, [var]}, env) do
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.