From af95739bbfeb2f2ed7816d2e18f8a775baa32f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zapa=C5=9Bnik?= Date: Thu, 11 Apr 2019 13:11:19 +0200 Subject: [PATCH 1/3] Add cross join --- lib/sqlite_ecto/connection.ex | 6 +++++- test/sqlite_ecto_test.exs | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/sqlite_ecto/connection.ex b/lib/sqlite_ecto/connection.ex index 32af5bcb..571dbe6c 100644 --- a/lib/sqlite_ecto/connection.ex +++ b/lib/sqlite_ecto/connection.ex @@ -276,12 +276,16 @@ if Code.ensure_loaded?(Sqlitex.Server) do [?\s | intersperse_map(joins, ?\s, fn %JoinExpr{on: %QueryExpr{expr: expr}, qual: qual, ix: ix, source: source} -> {join, name} = get_source(query, sources, ix, source) - [join_qual(qual), join, " AS ", name, " ON " | expr(expr, sources, query)] + [join_qual(qual), join, " AS ", name, join_on(qual, expr, sources, query)] end)] end + defp join_on(:cross, true, _sources, _query), do: [] + defp join_on(_qual, expr, sources, query), do: [" ON " | expr(expr, sources, query)] + defp join_qual(:inner), do: "INNER JOIN " defp join_qual(:left), do: "LEFT JOIN " + defp join_qual(:cross), do: "CROSS JOIN " defp join_qual(mode), do: raise ArgumentError, "join `#{inspect mode}` not supported by SQLite" defp where(%Query{wheres: wheres} = query, sources) do diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index 00f00ad8..a01aa2fa 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -660,10 +660,9 @@ defmodule Sqlite.Ecto2.Test do end test "cross join" do - assert_raise ArgumentError, "join `:cross` not supported by SQLite", fn -> - query = from(p in Schema, cross_join: c in Schema2, select: {p.id, c.id}) |> normalize() - all(query) - end + query = from(p in Schema, cross_join: c in Schema2, select: {p.id, c.id}) |> normalize() + assert all(query) == + "SELECT s0.\"id\", s1.\"id\" FROM \"schema\" AS s0 CROSS JOIN \"schema2\" AS s1" end test "join produces correct bindings" do From eadf306be701739c185dcfe94bd4bfee56d68f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zapa=C5=9Bnik?= Date: Thu, 11 Apr 2019 13:12:59 +0200 Subject: [PATCH 2/3] Support ecto 2.2.10 --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 8fded95e..03a6d18a 100644 --- a/mix.exs +++ b/mix.exs @@ -42,7 +42,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:decimal, "~> 1.5"}, {:excoveralls, "~> 0.9", only: :test}, {:ex_doc, "~> 0.20", runtime: false, only: :docs}, - {:ecto, "2.2.9"}, + {:ecto, "2.2.10"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index bba0bc51..a731f3c9 100644 --- a/mix.lock +++ b/mix.lock @@ -8,7 +8,7 @@ "decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.16", "3c1532e2f63ece4813fe900a16704b8e33264da35fdb0d8a1d05090a3022eef9", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"}, - "ecto": {:hex, :ecto, "2.2.9", "031d55df9bb430cb118e6f3026a87408d9ce9638737bda3871e5d727a3594aae", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, + "ecto": {:hex, :ecto, "2.2.10", "e7366dc82f48f8dd78fcbf3ab50985ceeb11cb3dc93435147c6e13f2cda0992e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "elixir_make": {:hex, :elixir_make, "0.4.2", "332c649d08c18bc1ecc73b1befc68c647136de4f340b548844efc796405743bf", [:mix], [], "hexpm"}, "esqlite": {:hex, :esqlite, "0.4.0", "8d0b88a774dceaec4fff0a6f63248efe811684591f186b6b21d4390be19bf1db", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.20.1", "88eaa16e67c505664fd6a66f42ddb962d424ad68df586b214b71443c69887123", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, From 430d7e792d0a6e127d67dcf3fd1309fa9c3a7e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zapa=C5=9Bnik?= Date: Thu, 11 Apr 2019 13:19:35 +0200 Subject: [PATCH 3/3] Support ecto 2.2.11 --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 03a6d18a..cb734e35 100644 --- a/mix.exs +++ b/mix.exs @@ -42,7 +42,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:decimal, "~> 1.5"}, {:excoveralls, "~> 0.9", only: :test}, {:ex_doc, "~> 0.20", runtime: false, only: :docs}, - {:ecto, "2.2.10"}, + {:ecto, "2.2.11"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index a731f3c9..fff8f165 100644 --- a/mix.lock +++ b/mix.lock @@ -8,7 +8,7 @@ "decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.16", "3c1532e2f63ece4813fe900a16704b8e33264da35fdb0d8a1d05090a3022eef9", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"}, - "ecto": {:hex, :ecto, "2.2.10", "e7366dc82f48f8dd78fcbf3ab50985ceeb11cb3dc93435147c6e13f2cda0992e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, + "ecto": {:hex, :ecto, "2.2.11", "4bb8f11718b72ba97a2696f65d247a379e739a0ecabf6a13ad1face79844791c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "elixir_make": {:hex, :elixir_make, "0.4.2", "332c649d08c18bc1ecc73b1befc68c647136de4f340b548844efc796405743bf", [:mix], [], "hexpm"}, "esqlite": {:hex, :esqlite, "0.4.0", "8d0b88a774dceaec4fff0a6f63248efe811684591f186b6b21d4390be19bf1db", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.20.1", "88eaa16e67c505664fd6a66f42ddb962d424ad68df586b214b71443c69887123", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},