Coder Social home page Coder Social logo

ex_sieve's People

Contributors

albertored avatar dotsent avatar drnikon avatar juise avatar valyukov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ex_sieve's Issues

Make Repo.filter() work with Ecto.Query (Ecto 3.4.4)

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

Error when attempting to filter by date

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"inwhere 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 :)

Does not work with ecto 2.1.3

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

ex_sieve_ecto_2_1_patch.diff.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.