From b1065867190e4df810b34f10e7189d8fa3555c41 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 09:55:24 -0700 Subject: [PATCH 01/21] Switch over to GitHub so we can track commit-by-commit. --- mix.exs | 2 +- mix.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index 39b2f58c..5a77fe3e 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, - {:ecto, "~> 2.1.0"}, + {:ecto, github: "elixir-ecto/ecto", ref: "219dea3842e3022dd46c64f1888c4c5bca9e8cf1"}, {:poison, "~> 2.2", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index 82d71d4e..f4cc64f7 100644 --- a/mix.lock +++ b/mix.lock @@ -4,10 +4,10 @@ "coverex": {:hex, :coverex, "1.4.13", "d90833b82bdd6a1ec05a6d971283debc3dd9611957489010e4b1ab0071a9ee6c", [:mix], [{:hackney, "~> 1.5", [hex: :hackney, repo: "hexpm", optional: false]}, {:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "credo": {:hex, :credo, "0.8.1", "137efcc99b4bc507c958ba9b5dff70149e971250813cbe7d4537ec7e36997402", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"}, "db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, - "decimal": {:hex, :decimal, "1.3.1", "157b3cedb2bfcb5359372a7766dd7a41091ad34578296e951f58a946fcab49c6", [:mix], [], "hexpm"}, + "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:hex, :ecto, "2.1.4", "d1ba932813ec0e0d9db481ef2c17777f1cefb11fc90fa7c142ff354972dfba7e", [: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": {:git, "https://github.com/elixir-ecto/ecto.git", "219dea3842e3022dd46c64f1888c4c5bca9e8cf1", [ref: "219dea3842e3022dd46c64f1888c4c5bca9e8cf1"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, From 3819ad3be5ffe03d40d49503c648669fe82a3c2a Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 10:07:15 -0700 Subject: [PATCH 02/21] Back out change in query interpolation test, which was apparently added in Ecto 2.1.x. --- test/sqlite_ecto_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index 8117188b..e0fccddc 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -607,7 +607,7 @@ defmodule Sqlite.Ecto2.Test do inner = Ecto.Queryable.to_query(Schema2) query = from(p in Schema, left_join: c in ^inner, select: {p.id, c.id}) |> normalize() assert SQL.all(query) == - "SELECT s0.\"id\", s1.\"id\" FROM \"schema\" AS s0 LEFT JOIN \"schema2\" AS s1 ON 1" + "SELECT s0.\"id\", s1.\"id\" FROM \"schema\" AS s0 INNER JOIN \"schema2\" AS s1 ON 1" end test "lateral join with fragment" do From 5bfb4b493de2793884aa1a2d9b6371c0fd69c326 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 10:08:22 -0700 Subject: [PATCH 03/21] Back out the Travis CI config change. We'll just do Ecto 2.2 support using the traditional PR validation. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index da2d7239..582c3426 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,3 @@ script: branches: only: - master - - ecto-2.2 From 9c0adbee4b4d9e4b1572c07198d65cf5e240694a Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 10:44:32 -0700 Subject: [PATCH 04/21] Advance to "Correctly list the available options for creating constraints" commit from 30 Dec 2016. --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 5a77fe3e..7520a7ae 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "219dea3842e3022dd46c64f1888c4c5bca9e8cf1"}, + {:ecto, github: "elixir-ecto/ecto", ref: "67327b47a316aee6b274b9924ddc3299fdc8986e"}, {:poison, "~> 2.2", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index f4cc64f7..4db1ccf7 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "219dea3842e3022dd46c64f1888c4c5bca9e8cf1", [ref: "219dea3842e3022dd46c64f1888c4c5bca9e8cf1"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "67327b47a316aee6b274b9924ddc3299fdc8986e", [ref: "67327b47a316aee6b274b9924ddc3299fdc8986e"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, From b1181e46dcdd33f23c6803f660c5b3c02280eeac Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 10:50:36 -0700 Subject: [PATCH 05/21] Advance to "Switch id fields to default to BIGINT" commit from 31 Dec 2016. --- lib/sqlite_ecto/connection.ex | 2 ++ mix.exs | 2 +- mix.lock | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/sqlite_ecto/connection.ex b/lib/sqlite_ecto/connection.ex index d089c1ce..df3cf954 100644 --- a/lib/sqlite_ecto/connection.ex +++ b/lib/sqlite_ecto/connection.ex @@ -765,6 +765,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do # precision regardless of the declared column type. Decimals are the # only exception. defp column_type(:serial, _opts), do: "INTEGER" + defp column_type(:bigserial, _opts), do: "INTEGER" defp column_type(:string, _opts), do: "TEXT" defp column_type(:map, _opts), do: "TEXT" defp column_type({:map, _}, _opts), do: "TEXT" @@ -794,6 +795,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do do: quote_name(name) defp reference_column_type(:serial, _opts), do: "INTEGER" + defp reference_column_type(:bigserial, _opts), do: "INTEGER" defp reference_column_type(type, opts), do: column_type(type, opts) defp reference_on_delete(:nilify_all), do: " ON DELETE SET NULL" diff --git a/mix.exs b/mix.exs index 7520a7ae..0d72cb1a 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "67327b47a316aee6b274b9924ddc3299fdc8986e"}, + {:ecto, github: "elixir-ecto/ecto", ref: "8728a6f4487bd1a0a61c3d22438f2bc1419a524e"}, {:poison, "~> 2.2", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index 4db1ccf7..f9a27445 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "67327b47a316aee6b274b9924ddc3299fdc8986e", [ref: "67327b47a316aee6b274b9924ddc3299fdc8986e"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "8728a6f4487bd1a0a61c3d22438f2bc1419a524e", [ref: "8728a6f4487bd1a0a61c3d22438f2bc1419a524e"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, From 702f2854620450de74a7e52cc5e22d41c564b293 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 11:06:30 -0700 Subject: [PATCH 06/21] Advance to "Keep utf-8 encoding in fragments" commit from 22 Jan 2017. --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 0d72cb1a..c82836ef 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "8728a6f4487bd1a0a61c3d22438f2bc1419a524e"}, + {:ecto, github: "elixir-ecto/ecto", ref: "277d50b11d4b13e94fe44b5ef66fd75172542f37"}, {:poison, "~> 2.2", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index f9a27445..91f91d79 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "8728a6f4487bd1a0a61c3d22438f2bc1419a524e", [ref: "8728a6f4487bd1a0a61c3d22438f2bc1419a524e"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "277d50b11d4b13e94fe44b5ef66fd75172542f37", [ref: "277d50b11d4b13e94fe44b5ef66fd75172542f37"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, From 5b5c031bbb706a4741b400f01f14abf5ed903ae2 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 11:09:26 -0700 Subject: [PATCH 07/21] Advance to "Ensure proper qualify for join with interpolated query" commit from 24 Jan 2017. --- mix.exs | 2 +- mix.lock | 2 +- test/sqlite_ecto_test.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index c82836ef..444b91d5 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "277d50b11d4b13e94fe44b5ef66fd75172542f37"}, + {:ecto, github: "elixir-ecto/ecto", ref: "ca21f6ed6a5101bf3f04e12c33aed0a1e518f606"}, {:poison, "~> 2.2", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index 91f91d79..ce0e73fc 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "277d50b11d4b13e94fe44b5ef66fd75172542f37", [ref: "277d50b11d4b13e94fe44b5ef66fd75172542f37"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "ca21f6ed6a5101bf3f04e12c33aed0a1e518f606", [ref: "ca21f6ed6a5101bf3f04e12c33aed0a1e518f606"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index e0fccddc..8117188b 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -607,7 +607,7 @@ defmodule Sqlite.Ecto2.Test do inner = Ecto.Queryable.to_query(Schema2) query = from(p in Schema, left_join: c in ^inner, select: {p.id, c.id}) |> normalize() assert SQL.all(query) == - "SELECT s0.\"id\", s1.\"id\" FROM \"schema\" AS s0 INNER JOIN \"schema2\" AS s1 ON 1" + "SELECT s0.\"id\", s1.\"id\" FROM \"schema\" AS s0 LEFT JOIN \"schema2\" AS s1 ON 1" end test "lateral join with fragment" do From 874b8efb4168b854e7421a93e6c938bb17313319 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 12:55:20 -0700 Subject: [PATCH 08/21] Update to "Add table prefix for set field in update_all query" commit from 18 May 2017. Drop support for Elixir 1.3.x, as was done in corresponding Ecto master branch during that time. --- .travis.yml | 5 ----- lib/sqlite_ecto/connection.ex | 2 +- mix.exs | 4 ++-- mix.lock | 2 +- test/sqlite_ecto_test.exs | 4 ++-- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 582c3426..6ed99fb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: elixir elixir: - - 1.3.4 - 1.4.4 - 1.5.1 @@ -12,10 +11,6 @@ otp_release: matrix: exclude: - - elixir: 1.3.4 - otp_release: 19.3 - - elixir: 1.3.4 - otp_release: 20.0 - elixir: 1.4.4 otp_release: 20.0 - elixir: 1.5.1 diff --git a/lib/sqlite_ecto/connection.ex b/lib/sqlite_ecto/connection.ex index df3cf954..0b35a85c 100644 --- a/lib/sqlite_ecto/connection.ex +++ b/lib/sqlite_ecto/connection.ex @@ -750,7 +750,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do do: [] defp index_expr(literal) when is_binary(literal), - do: literal + do: [?(, literal, ?)] defp index_expr(literal), do: quote_name(literal) diff --git a/mix.exs b/mix.exs index 444b91d5..9e1f55a8 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule Sqlite.Ecto2.Mixfile do [app: :sqlite_ecto2, version: "2.0.2", name: "Sqlite.Ecto2", - elixir: "~> 1.3.4 or ~> 1.4", + elixir: "~> 1.4", elixirc_options: [warnings_as_errors: true], deps: deps(), elixirc_paths: elixirc_paths(Mix.env), @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "ca21f6ed6a5101bf3f04e12c33aed0a1e518f606"}, + {:ecto, github: "elixir-ecto/ecto", ref: "d60176e1431fa39c2900f6418461a60a83907712"}, {:poison, "~> 2.2", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index ce0e73fc..614cd2e0 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "ca21f6ed6a5101bf3f04e12c33aed0a1e518f606", [ref: "ca21f6ed6a5101bf3f04e12c33aed0a1e518f606"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "d60176e1431fa39c2900f6418461a60a83907712", [ref: "d60176e1431fa39c2900f6418461a60a83907712"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index 8117188b..56fc49af 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -1024,7 +1024,7 @@ defmodule Sqlite.Ecto2.Test do create = {:create, index(:posts, ["lower(permalink)"], name: "posts$main")} assert execute_ddl(create) == - [~s|CREATE INDEX "posts$main" ON "posts" (lower(permalink))|] + [~s|CREATE INDEX "posts$main" ON "posts" ((lower(permalink)))|] end test "create index if not exists" do @@ -1040,7 +1040,7 @@ defmodule Sqlite.Ecto2.Test do create = {:create, index(:posts, ["lower(permalink)"], name: "posts$main", prefix: :foo)} assert execute_ddl(create) == - [~s|CREATE INDEX "posts$main" ON "foo"."posts" (lower(permalink))|] + [~s|CREATE INDEX "posts$main" ON "foo"."posts" ((lower(permalink)))|] end test "create index with comment" do From fb1d191828065bb0c12e865740a6c0e86598272a Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 13:06:09 -0700 Subject: [PATCH 09/21] Update deps to match Ecto 2.2 branch as of 18 May 2017. --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 9e1f55a8..00243491 100644 --- a/mix.exs +++ b/mix.exs @@ -40,7 +40,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, {:ecto, github: "elixir-ecto/ecto", ref: "d60176e1431fa39c2900f6418461a60a83907712"}, - {:poison, "~> 2.2", optional: true}, + {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, {:sqlitex, "~> 1.3.2 or ~> 1.4"}] diff --git a/mix.lock b/mix.lock index 614cd2e0..18aadb8b 100644 --- a/mix.lock +++ b/mix.lock @@ -14,7 +14,7 @@ "idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], [], "hexpm"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, - "poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], [], "hexpm"}, + "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}, "postgrex": {:hex, :postgrex, "0.13.3", "c277cfb2a9c5034d445a722494c13359e361d344ef6f25d604c2353185682bfc", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"}, "sbroker": {:hex, :sbroker, "1.0.0", "28ff1b5e58887c5098539f236307b36fe1d3edaa2acff9d6a3d17c2dcafebbd0", [:rebar3], [], "hexpm"}, From 1b38c81eb0f3dc608a0e8240aa6b83a858ffc965 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 13:16:15 -0700 Subject: [PATCH 10/21] Advance to "Allow map updates in subqueries" commit from 18 May 2017. --- integration/hack_out_incompatible_tests.sh | 10 ++++++++-- mix.exs | 2 +- mix.lock | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/integration/hack_out_incompatible_tests.sh b/integration/hack_out_incompatible_tests.sh index 8ad08f34..d64aa39a 100755 --- a/integration/hack_out_incompatible_tests.sh +++ b/integration/hack_out_incompatible_tests.sh @@ -19,7 +19,11 @@ sed -i "" '/test "Repo.insert_all escape/ i\ @tag :insert_cell_wise_defaults ' deps/ecto/integration_test/sql/sql.exs -sed -i "" '/subqueries with select expression/ i\ +sed -i "" '/subqueries with map and select expression/ i\ + @tag :map_boolean_in_subquery +' deps/ecto/integration_test/sql/subquery.exs + +sed -i "" '/subqueries with map update and select expression/ i\ @tag :map_boolean_in_subquery ' deps/ecto/integration_test/sql/subquery.exs @@ -31,6 +35,8 @@ sed -i '/failing child foreign key/ i @tag :foreign_key_constraint' deps/ecto/in sed -i '/test "Repo.insert_all escape/ i @tag :insert_cell_wise_defaults' deps/ecto/integration_test/sql/sql.exs -sed -i '/subqueries with select expression/ i @tag :map_boolean_in_subquery' deps/ecto/integration_test/sql/subquery.exs +sed -i '/subqueries with map and select expression/ i @tag :map_boolean_in_subquery' deps/ecto/integration_test/sql/subquery.exs + +sed -i '/subqueries with map update and select expression/ i @tag :map_boolean_in_subquery' deps/ecto/integration_test/sql/subquery.exs fi diff --git a/mix.exs b/mix.exs index 00243491..28dd7da2 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "d60176e1431fa39c2900f6418461a60a83907712"}, + {:ecto, github: "elixir-ecto/ecto", ref: "4c632d326a9d593be73289fa84eedfad53c92085"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index 18aadb8b..df712570 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "d60176e1431fa39c2900f6418461a60a83907712", [ref: "d60176e1431fa39c2900f6418461a60a83907712"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "4c632d326a9d593be73289fa84eedfad53c92085", [ref: "4c632d326a9d593be73289fa84eedfad53c92085"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, From 8d5b689d1ee690ea98f86348c28479895195f2c7 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 15:07:32 -0700 Subject: [PATCH 11/21] Advance to "Introduce new multiple primary key error" commit from 03 Aug 2017. --- lib/sqlite_ecto/connection.ex | 13 ++++++++----- mix.exs | 2 +- mix.lock | 2 +- test/sqlite_ecto_test.exs | 27 +++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/sqlite_ecto/connection.ex b/lib/sqlite_ecto/connection.ex index 0b35a85c..c01d3ccb 100644 --- a/lib/sqlite_ecto/connection.ex +++ b/lib/sqlite_ecto/connection.ex @@ -65,7 +65,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do {:ok, value} = Ecto.DataType.dump(data_type) value %{} = value -> - json_library().encode!(value) + Ecto.Adapter.json_library().encode!(value) value -> value end @@ -741,11 +741,15 @@ if Code.ensure_loaded?(Sqlitex.Server) do do: [" DEFAULT '", escape_string(literal), ?'] defp default_expr({:ok, literal}, _type) when is_number(literal) or is_boolean(literal), do: [" DEFAULT ", to_string(literal)] + defp default_expr({:ok, %{} = map}, :map) do + default = Ecto.Adapter.json_library().encode!(map) + [" DEFAULT ", single_quote(default)] + end defp default_expr({:ok, {:fragment, expr}}, _type), do: [" DEFAULT ", expr] defp default_expr({:ok, expr}, type), do: raise(ArgumentError, "unknown default `#{inspect expr}` for type `#{inspect type}`. " <> - ":default may be a string, number, boolean, empty list or a fragment(...)") + ":default may be a string, number, boolean, empty list, map (when type is Map), or a fragment(...)") defp default_expr(:error, _), do: [] @@ -845,6 +849,8 @@ if Code.ensure_loaded?(Sqlitex.Server) do [?", name, ?"] end + defp single_quote(value), do: [?', escape_string(value), ?'] + defp intersperse_map(list, separator, mapper, acc \\ []) defp intersperse_map([], _separator, _mapper, acc), do: acc @@ -879,8 +885,5 @@ if Code.ensure_loaded?(Sqlitex.Server) do defp error!(query, message) do raise Ecto.QueryError, query: query, message: message end - - # Use Ecto's JSON library (currently Poison) for embedded JSON datatypes. - defp json_library, do: Application.get_env(:ecto, :json_library) end end diff --git a/mix.exs b/mix.exs index 28dd7da2..a44917e7 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.15", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "4c632d326a9d593be73289fa84eedfad53c92085"}, + {:ecto, github: "elixir-ecto/ecto", ref: "d46b9bdaa940e124a0fb9fd984d71327db958215"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index df712570..c1045436 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "4c632d326a9d593be73289fa84eedfad53c92085", [ref: "4c632d326a9d593be73289fa84eedfad53c92085"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "d46b9bdaa940e124a0fb9fd984d71327db958215", [ref: "d46b9bdaa940e124a0fb9fd984d71327db958215"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index 56fc49af..48793779 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -951,6 +951,33 @@ defmodule Sqlite.Ecto2.Test do end end + test "create table with a map column, and an empty map default" do + create = {:create, table(:posts), + [ + {:add, :a, :map, [default: %{}]} + ] + } + assert execute_ddl(create) == [~s|CREATE TABLE "posts" ("a" TEXT DEFAULT '{}')|] + end + + test "create table with a map column, and a map default with values" do + create = {:create, table(:posts), + [ + {:add, :a, :map, [default: %{foo: "bar", baz: "boom"}]} + ] + } + assert execute_ddl(create) == [~s|CREATE TABLE "posts" ("a" TEXT DEFAULT '{"foo":"bar","baz":"boom"}')|] + end + + test "create table with a map column, and a string default" do + create = {:create, table(:posts), + [ + {:add, :a, :map, [default: ~s|{"foo":"bar","baz":"boom"}|]} + ] + } + assert execute_ddl(create) == [~s|CREATE TABLE "posts" ("a" TEXT DEFAULT '{"foo":"bar","baz":"boom"}')|] + end + test "drop table" do drop = {:drop, table(:posts)} assert execute_ddl(drop) == [~s|DROP TABLE "posts"|] From 8b2b000ab7720bd0d5429a9dab63a03bb10f80c8 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 15:08:45 -0700 Subject: [PATCH 12/21] Update to ex_doc 0.16.x to match Ecto changes. --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index a44917e7..f413304f 100644 --- a/mix.exs +++ b/mix.exs @@ -38,7 +38,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:decimal, "~> 1.2"}, {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, - {:ex_doc, "~> 0.15", only: :dev}, + {:ex_doc, "~> 0.16", only: :dev}, {:ecto, github: "elixir-ecto/ecto", ref: "d46b9bdaa940e124a0fb9fd984d71327db958215"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, diff --git a/mix.lock b/mix.lock index c1045436..bdae5823 100644 --- a/mix.lock +++ b/mix.lock @@ -9,7 +9,7 @@ "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "d46b9bdaa940e124a0fb9fd984d71327db958215", [ref: "d46b9bdaa940e124a0fb9fd984d71327db958215"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, "idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], [], "hexpm"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, From f4eab9c482014c2404409eba603df9ab3fbeeb44 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 17:29:58 -0700 Subject: [PATCH 13/21] Advance to "Tests for subquery select parameter count" commit from 04 Aug 2017. --- mix.exs | 2 +- mix.lock | 2 +- test/sqlite_ecto_test.exs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index f413304f..b201baa6 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.16", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "d46b9bdaa940e124a0fb9fd984d71327db958215"}, + {:ecto, github: "elixir-ecto/ecto", ref: "82aeb451b43928f51cb6311169ccdcfb51be8574"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index bdae5823..c3b50e65 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "d46b9bdaa940e124a0fb9fd984d71327db958215", [ref: "d46b9bdaa940e124a0fb9fd984d71327db958215"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "82aeb451b43928f51cb6311169ccdcfb51be8574", [ref: "82aeb451b43928f51cb6311169ccdcfb51be8574"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index 48793779..5f123fc3 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -636,6 +636,41 @@ defmodule Sqlite.Ecto2.Test do "SELECT s0.\"id\", s2.\"id\" FROM \"schema\" AS s0 INNER JOIN \"schema2\" AS s1 ON 1 INNER JOIN \"schema2\" AS s2 ON 1" end + describe "query interpolation parameters" do + test "self join on subquery" do + subquery = select(Schema, [r], %{x: r.x, y: r.y}) + query = subquery |> join(:inner, [c], p in subquery(subquery), true) |> normalize + assert SQL.all(query) == + ~s{SELECT s0."x", s0."y" FROM "schema" AS s0 INNER JOIN } <> + ~s{(SELECT s0."x" AS "x", s0."y" AS "y" FROM "schema" AS s0) } <> + ~s{AS s1 ON 1} + end + + # Disabled for now. Also broken in corresponding Ecto test for Postgres adapter. + # test "self join on subquery with fragment" do + # subquery = select(Schema, [r], %{string: fragment("downcase(?)", ^"string")}) + # query = subquery |> join(:inner, [c], p in subquery(subquery), true) |> normalize + # assert SQL.all(query) == + # ~s{SELECT downcase(?1) FROM "schema" AS s0 INNER JOIN } <> + # ~s{(SELECT downcase(?2) AS "string" FROM "schema" AS s0) } <> + # ~s{AS s1 ON 1} + # end + # + # test "join on subquery with simple select" do + # subquery = select(Schema, [r], %{x: ^999, w: ^888}) + # query = Schema + # |> select([r], %{y: ^666}) + # |> join(:inner, [c], p in subquery(subquery), true) + # |> where([a, b], a.x == ^111) + # |> normalize + # + # assert SQL.all(query) == + # ~s{SELECT ?1 FROM "schema" AS s0 INNER JOIN } <> + # ~s{(SELECT ?2 AS "x", ?3 AS "w" FROM "schema" AS s0) AS s1 ON 1 } <> + # ~s{WHERE (s0."x" = ?4)} + # end + end + ## Associations test "association join belongs_to" do From 6d2e06001618e06ff74aa3cdf848756b96272a6b Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 17:36:12 -0700 Subject: [PATCH 14/21] Drop support for OTP 18.0. Continue to test against OTP 18.2 as does "current" Ecto release. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6ed99fb3..0d45002a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ elixir: - 1.5.1 otp_release: - - 18.0 + - 18.2 - 19.3 - 20.0 @@ -14,7 +14,7 @@ matrix: - elixir: 1.4.4 otp_release: 20.0 - elixir: 1.5.1 - otp_release: 18.0 + otp_release: 18.2 script: - mix deps.get && ./integration/hack_out_incompatible_tests.sh && mix test --cover From d118fb98c0294d834a35a0e6407c01014a01bb39 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 18:09:12 -0700 Subject: [PATCH 15/21] Advance to "Introduce an AST for preprocessing + postprocessing" commit from 04 Aug 2017. --- lib/sqlite_ecto/connection.ex | 20 ++++++++++---------- mix.exs | 2 +- mix.lock | 2 +- test/sqlite_ecto_test.exs | 3 ++- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/sqlite_ecto/connection.ex b/lib/sqlite_ecto/connection.ex index c01d3ccb..68ec2d5e 100644 --- a/lib/sqlite_ecto/connection.ex +++ b/lib/sqlite_ecto/connection.ex @@ -328,13 +328,10 @@ if Code.ensure_loaded?(Sqlitex.Server) do quote_qualified_name(field, sources, idx) end - defp expr({:&, _, [idx, fields, _counter]}, sources, query) do - {source, name, schema} = elem(sources, idx) - if is_nil(schema) and is_nil(fields) do - error!(query, "SQLite does not support selecting all fields from #{source} without a schema. " <> + defp expr({:&, _, [idx]}, sources, query) do + {source, _name, _schema} = elem(sources, idx) + error!(query, "SQLite does not support selecting all fields from #{source} without a schema. " <> "Please specify a schema or specify exactly which fields you want to select") - end - intersperse_map(fields, ", ", &[name, ?. | quote_name(&1)]) end defp expr({:in, _, [left, right]}, sources, query) when is_list(right) do @@ -363,8 +360,8 @@ if Code.ensure_loaded?(Sqlitex.Server) do ["NOT (", expr(expr, sources, query), ?)] end - defp expr(%Ecto.SubQuery{query: query, fields: fields}, _sources, _query) do - query.select.fields |> put_in(fields) |> all() + defp expr(%Ecto.SubQuery{query: query}, _sources, _query) do + all(query) end defp expr({:fragment, _, [kw]}, _sources, query) when is_list(kw) or tuple_size(kw) == 3 do @@ -476,10 +473,11 @@ if Code.ensure_loaded?(Sqlitex.Server) do # transaction and trigger. See corresponding code in Sqlitex. defp returning(%Query{select: nil}, _sources, _cmd), do: [] - defp returning(%Query{select: %{fields: [{:&, [], [_, fields, _]}]}}, sources, cmd) do + defp returning(%Query{select: %{fields: field_tuples}}, sources, cmd) do cmd = cmd |> Atom.to_string |> String.upcase table = table_from_first_source(sources) - fields = Enum.map_join([table | fields], ",", "e_id/1) + fields = Enum.map_join([table | Enum.map(field_tuples, &field_from_field_tuple/1)], + ",", "e_id/1) [@pseudo_returning_statement, cmd, ?\s, fields] end @@ -491,6 +489,8 @@ if Code.ensure_loaded?(Sqlitex.Server) do |> String.trim("\"") end + defp field_from_field_tuple({{:., [], [{:&, [], [0]}, f]}, [], []}), do: f + defp returning_clause(_prefix, _table, [], _cmd), do: [] defp returning_clause(prefix, table, returning, cmd) do fields = Enum.map_join([{prefix, table} | returning], ",", "e_id/1) diff --git a/mix.exs b/mix.exs index b201baa6..d54a17fb 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.16", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "82aeb451b43928f51cb6311169ccdcfb51be8574"}, + {:ecto, github: "elixir-ecto/ecto", ref: "095121307a2b9c2ffbea9963f7732b8ff5e26f65"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index c3b50e65..0f0ed395 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "82aeb451b43928f51cb6311169ccdcfb51be8574", [ref: "82aeb451b43928f51cb6311169ccdcfb51be8574"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "095121307a2b9c2ffbea9963f7732b8ff5e26f65", [ref: "095121307a2b9c2ffbea9963f7732b8ff5e26f65"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index 5f123fc3..60a1addf 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -98,7 +98,8 @@ defmodule Sqlite.Ecto2.Test do defp normalize(query, operation \\ :all, counter \\ 0) do {query, _params, _key} = Ecto.Query.Planner.prepare(query, operation, Sqlite.Ecto2, counter) - Ecto.Query.Planner.normalize(query, operation, Sqlite.Ecto2, counter) + {query, _} = Ecto.Query.Planner.normalize(query, operation, Sqlite.Ecto2, counter) + query end test "from" do From f4fddd1715e96322891ce3440cd985292906caf9 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 18:27:28 -0700 Subject: [PATCH 16/21] Advance to "Mention the migration timestamp is in UTC" commit from 18 Aug 2017. --- lib/sqlite_ecto/connection.ex | 19 +-- mix.exs | 2 +- mix.lock | 2 +- test/sqlite_ecto_test.exs | 313 ++++++++++++++++++---------------- 4 files changed, 174 insertions(+), 162 deletions(-) diff --git a/lib/sqlite_ecto/connection.ex b/lib/sqlite_ecto/connection.ex index 68ec2d5e..6d57369f 100644 --- a/lib/sqlite_ecto/connection.ex +++ b/lib/sqlite_ecto/connection.ex @@ -93,7 +93,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do limit = limit(query, sources) offset = offset(query, sources) - IO.iodata_to_binary([select, from, join, where, group_by, having, order_by, limit, offset]) + [select, from, join, where, group_by, having, order_by, limit, offset] end def update_all(%Ecto.Query{joins: [_ | _]}) do @@ -107,7 +107,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do fields = update_fields(query, sources) where = where(%{query | wheres: query.wheres}, sources) - IO.iodata_to_binary([prefix, fields, where | returning(query, sources, :update)]) + [prefix, fields, where | returning(query, sources, :update)] end def delete_all(%Ecto.Query{joins: [_ | _]}) do @@ -119,7 +119,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do where = where(%{query | wheres: query.wheres}, sources) - IO.iodata_to_binary(["DELETE FROM ", from, where | returning(query, sources, :delete)]) + ["DELETE FROM ", from, where | returning(query, sources, :delete)] end def insert(prefix, table, header, rows, on_conflict, returning) do @@ -136,8 +136,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do _ -> raise ArgumentError, "Upsert in SQLite must use on_conflict: :nothing" end returning = returning_clause(prefix, table, returning, "INSERT") - IO.iodata_to_binary(["INSERT", on_conflict, " INTO ", quote_table(prefix, table), - values, returning]) + ["INSERT", on_conflict, " INTO ", quote_table(prefix, table), values, returning] end defp insert_all(rows, counter) do @@ -168,8 +167,8 @@ if Code.ensure_loaded?(Sqlitex.Server) do return = returning_clause(prefix, table, returning, "UPDATE") - IO.iodata_to_binary(["UPDATE ", quote_table(prefix, table), " SET ", - fields, " WHERE ", filters | return]) + ["UPDATE ", quote_table(prefix, table), " SET ", + fields, " WHERE ", filters | return] end def delete(prefix, table, filters, returning) do @@ -177,8 +176,8 @@ if Code.ensure_loaded?(Sqlitex.Server) do {[quote_name(field), " = ?" | Integer.to_string(acc)], acc + 1} end) - IO.iodata_to_binary(["DELETE FROM ", quote_table(prefix, table), " WHERE ", - filters | returning_clause(prefix, table, returning, "DELETE")]) + ["DELETE FROM ", quote_table(prefix, table), " WHERE ", + filters | returning_clause(prefix, table, returning, "DELETE")] end ## Query generation @@ -754,7 +753,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do do: [] defp index_expr(literal) when is_binary(literal), - do: [?(, literal, ?)] + do: literal defp index_expr(literal), do: quote_name(literal) diff --git a/mix.exs b/mix.exs index d54a17fb..ea5b0182 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.16", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "095121307a2b9c2ffbea9963f7732b8ff5e26f65"}, + {:ecto, github: "elixir-ecto/ecto", ref: "0b12f8f8ff7f1e3259fe6302e30dca85eb8b21c1"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index 0f0ed395..dc9fc564 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "095121307a2b9c2ffbea9963f7732b8ff5e26f65", [ref: "095121307a2b9c2ffbea9963f7732b8ff5e26f65"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "0b12f8f8ff7f1e3259fe6302e30dca85eb8b21c1", [ref: "0b12f8f8ff7f1e3259fe6302e30dca85eb8b21c1"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index 60a1addf..e5a2489a 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -102,291 +102,308 @@ defmodule Sqlite.Ecto2.Test do query end + defp all(query), do: query |> SQL.all |> IO.iodata_to_binary() + defp update_all(query), do: query |> SQL.update_all |> IO.iodata_to_binary() + defp delete_all(query), do: query |> SQL.delete_all |> IO.iodata_to_binary() + defp execute_ddl(query), do: query |> SQL.execute_ddl |> Enum.map(&IO.iodata_to_binary/1) + + defp insert(prefx, table, header, rows, on_conflict, returning) do + IO.iodata_to_binary SQL.insert(prefx, table, header, rows, on_conflict, returning) + end + + defp update(prefx, table, fields, filter, returning) do + IO.iodata_to_binary SQL.update(prefx, table, fields, filter, returning) + end + + defp delete(prefx, table, filter, returning) do + IO.iodata_to_binary SQL.delete(prefx, table, filter, returning) + end + test "from" do query = Schema |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0} end test "from without schema" do query = "posts" |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT p0."x" FROM "posts" AS p0} + assert all(query) == ~s{SELECT p0."x" FROM "posts" AS p0} query = "posts" |> select([:x]) |> normalize - assert SQL.all(query) == ~s{SELECT p0."x" FROM "posts" AS p0} + assert all(query) == ~s{SELECT p0."x" FROM "posts" AS p0} assert_raise Ecto.QueryError, ~r"SQLite does not support selecting all fields from \"posts\" without a schema", fn -> - SQL.all from(p in "posts", select: p) |> normalize() + all from(p in "posts", select: p) |> normalize() end end test "from with subquery" do query = subquery("posts" |> select([r], %{x: r.x, y: r.y})) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM (SELECT p0."x" AS "x", p0."y" AS "y" FROM "posts" AS p0) AS s0} + assert all(query) == ~s{SELECT s0."x" FROM (SELECT p0."x" AS "x", p0."y" AS "y" FROM "posts" AS p0) AS s0} query = subquery("posts" |> select([r], %{x: r.x, z: r.y})) |> select([r], r) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x", s0."z" FROM (SELECT p0."x" AS "x", p0."y" AS "z" FROM "posts" AS p0) AS s0} + assert all(query) == ~s{SELECT s0."x", s0."z" FROM (SELECT p0."x" AS "x", p0."y" AS "z" FROM "posts" AS p0) AS s0} end test "select" do query = Schema |> select([r], {r.x, r.y}) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} query = Schema |> select([r], [r.x, r.y]) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} query = Schema |> select([r], struct(r, [:x, :y])) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} end test "aggregates" do query = Schema |> select([r], count(r.x)) |> normalize - assert SQL.all(query) == ~s{SELECT count(s0."x") FROM "schema" AS s0} + assert all(query) == ~s{SELECT count(s0."x") FROM "schema" AS s0} query = Schema |> select([r], count(r.x, :distinct)) |> normalize - assert SQL.all(query) == ~s{SELECT count(DISTINCT s0."x") FROM "schema" AS s0} + assert all(query) == ~s{SELECT count(DISTINCT s0."x") FROM "schema" AS s0} end test "distinct" do assert_raise ArgumentError, "DISTINCT with multiple columns is not supported by SQLite", fn -> query = Schema |> distinct([r], r.x) |> select([r], {r.x, r.y}) |> normalize - SQL.all(query) + all(query) end assert_raise ArgumentError, "DISTINCT with multiple columns is not supported by SQLite", fn -> query = Schema |> distinct([r], desc: r.x) |> select([r], {r.x, r.y}) |> normalize - SQL.all(query) + all(query) end assert_raise ArgumentError, "DISTINCT with multiple columns is not supported by SQLite", fn -> query = Schema |> distinct([r], 2) |> select([r], r.x) |> normalize - SQL.all(query) + all(query) end assert_raise ArgumentError, "DISTINCT with multiple columns is not supported by SQLite", fn -> query = Schema |> distinct([r], [r.x, r.y]) |> select([r], {r.x, r.y}) |> normalize - SQL.all(query) + all(query) end query = Schema |> distinct([r], true) |> select([r], {r.x, r.y}) |> normalize - assert SQL.all(query) == ~s{SELECT DISTINCT s0."x", s0."y" FROM "schema" AS s0} + assert all(query) == ~s{SELECT DISTINCT s0."x", s0."y" FROM "schema" AS s0} query = Schema |> distinct([r], false) |> select([r], {r.x, r.y}) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} query = Schema |> distinct(true) |> select([r], {r.x, r.y}) |> normalize - assert SQL.all(query) == ~s{SELECT DISTINCT s0."x", s0."y" FROM "schema" AS s0} + assert all(query) == ~s{SELECT DISTINCT s0."x", s0."y" FROM "schema" AS s0} query = Schema |> distinct(false) |> select([r], {r.x, r.y}) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0} end test "distinct with order by" do assert_raise ArgumentError, "DISTINCT with multiple columns is not supported by SQLite", fn -> query = Schema |> order_by([r], [r.y]) |> distinct([r], desc: r.x) |> select([r], r.x) |> normalize - SQL.all(query) + all(query) end end test "where" do query = Schema |> where([r], r.x == 42) |> where([r], r.y != 43) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 WHERE (s0."x" = 42) AND (s0."y" != 43)} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 WHERE (s0."x" = 42) AND (s0."y" != 43)} end test "or_where" do query = Schema |> or_where([r], r.x == 42) |> or_where([r], r.y != 43) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 WHERE (s0."x" = 42) OR (s0."y" != 43)} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 WHERE (s0."x" = 42) OR (s0."y" != 43)} query = Schema |> or_where([r], r.x == 42) |> or_where([r], r.y != 43) |> where([r], r.z == 44) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 WHERE ((s0."x" = 42) OR (s0."y" != 43)) AND (s0."z" = 44)} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 WHERE ((s0."x" = 42) OR (s0."y" != 43)) AND (s0."z" = 44)} end test "order by" do query = Schema |> order_by([r], r.x) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 ORDER BY s0."x"} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 ORDER BY s0."x"} query = Schema |> order_by([r], [r.x, r.y]) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 ORDER BY s0."x", s0."y"} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 ORDER BY s0."x", s0."y"} query = Schema |> order_by([r], [asc: r.x, desc: r.y]) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 ORDER BY s0."x", s0."y" DESC} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 ORDER BY s0."x", s0."y" DESC} query = Schema |> order_by([r], []) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0} end test "limit and offset" do query = Schema |> limit([r], 3) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 LIMIT 3} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 LIMIT 3} query = Schema |> offset([r], 5) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 OFFSET 5} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 OFFSET 5} query = Schema |> offset([r], 5) |> limit([r], 3) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 LIMIT 3 OFFSET 5} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 LIMIT 3 OFFSET 5} end test "lock" do assert_raise ArgumentError, "locks are not supported by SQLite", fn -> query = Schema |> lock("FOR SHARE NOWAIT") |> select([], 0) |> normalize - SQL.all(query) + all(query) end end test "string escape" do query = "schema" |> where(foo: "'\\ ") |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM \"schema\" AS s0 WHERE (s0.\"foo\" = '''\\ ')} + assert all(query) == ~s{SELECT 1 FROM \"schema\" AS s0 WHERE (s0.\"foo\" = '''\\ ')} query = "schema" |> where(foo: "'") |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = '''')} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = '''')} end test "binary ops" do query = Schema |> select([r], r.x == 2) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" = 2 FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" = 2 FROM "schema" AS s0} query = Schema |> select([r], r.x != 2) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" != 2 FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" != 2 FROM "schema" AS s0} query = Schema |> select([r], r.x <= 2) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" <= 2 FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" <= 2 FROM "schema" AS s0} query = Schema |> select([r], r.x >= 2) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" >= 2 FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" >= 2 FROM "schema" AS s0} query = Schema |> select([r], r.x < 2) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" < 2 FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" < 2 FROM "schema" AS s0} query = Schema |> select([r], r.x > 2) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" > 2 FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" > 2 FROM "schema" AS s0} end test "is_nil" do query = Schema |> select([r], is_nil(r.x)) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" IS NULL FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" IS NULL FROM "schema" AS s0} query = Schema |> select([r], not is_nil(r.x)) |> normalize - assert SQL.all(query) == ~s{SELECT NOT (s0."x" IS NULL) FROM "schema" AS s0} + assert all(query) == ~s{SELECT NOT (s0."x" IS NULL) FROM "schema" AS s0} end test "fragments" do query = Schema |> select([r], fragment("ltrim(?)", r.x)) |> normalize - assert SQL.all(query) == ~s{SELECT ltrim(s0."x") FROM "schema" AS s0} + assert all(query) == ~s{SELECT ltrim(s0."x") FROM "schema" AS s0} value = 13 query = Schema |> select([r], fragment("ltrim(?, ?)", r.x, ^value)) |> normalize - assert SQL.all(query) == ~s{SELECT ltrim(s0."x", ?1) FROM "schema" AS s0} + assert all(query) == ~s{SELECT ltrim(s0."x", ?1) FROM "schema" AS s0} query = Schema |> select([], fragment(title: 2)) |> normalize assert_raise Ecto.QueryError, ~r"SQLite adapter does not support keyword or interpolated fragments", fn -> - SQL.all(query) + all(query) end end test "literals" do query = "schema" |> where(foo: true) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 1)} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 1)} query = "schema" |> where(foo: false) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 0)} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 0)} query = "schema" |> where(foo: "abc") |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 'abc')} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 'abc')} query = "schema" |> where(foo: <<0, ?a, ?b, ?c>>) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = X'00616263')} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = X'00616263')} query = "schema" |> where(foo: 123) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 123)} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 123)} query = "schema" |> where(foo: 123.0) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 123.0)} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 WHERE (s0."foo" = 123.0)} end test "tagged type" do query = Schema |> select([], type(^"601d74e4-a8d3-4b6e-8365-eddb4c893327", Ecto.UUID)) |> normalize - assert SQL.all(query) == ~s{SELECT CAST (?1 AS TEXT) FROM "schema" AS s0} + assert all(query) == ~s{SELECT CAST (?1 AS TEXT) FROM "schema" AS s0} assert_raise ArgumentError, "Array type is not supported by SQLite", fn -> query = Schema |> select([], type(^[1, 2, 3], {:array, :integer})) |> normalize - SQL.all(query) + all(query) end end test "nested expressions" do z = 123 query = from(r in Schema, []) |> select([r], r.x > 0 and (r.y > ^(-z)) or true) |> normalize - assert SQL.all(query) == ~s{SELECT ((s0."x" > 0) AND (s0."y" > ?1)) OR 1 FROM "schema" AS s0} + assert all(query) == ~s{SELECT ((s0."x" > 0) AND (s0."y" > ?1)) OR 1 FROM "schema" AS s0} end test "in expression" do query = Schema |> select([e], 1 in []) |> normalize - assert SQL.all(query) == ~s{SELECT 1 IN () FROM "schema" AS s0} + assert all(query) == ~s{SELECT 1 IN () FROM "schema" AS s0} query = Schema |> select([e], 1 in [1, e.x, 3]) |> normalize - assert SQL.all(query) == ~s{SELECT 1 IN (1,s0."x",3) FROM "schema" AS s0} + assert all(query) == ~s{SELECT 1 IN (1,s0."x",3) FROM "schema" AS s0} query = Schema |> select([e], 1 in ^[]) |> normalize - assert SQL.all(query) == ~s{SELECT 1 IN () FROM "schema" AS s0} + assert all(query) == ~s{SELECT 1 IN () FROM "schema" AS s0} query = Schema |> select([e], 1 in ^[1, 2, 3]) |> normalize - assert SQL.all(query) == ~s{SELECT 1 IN (?1,?2,?3) FROM "schema" AS s0} + assert all(query) == ~s{SELECT 1 IN (?1,?2,?3) FROM "schema" AS s0} query = Schema |> select([e], 1 in [1, ^2, 3]) |> normalize - assert SQL.all(query) == ~s{SELECT 1 IN (1,?1,3) FROM "schema" AS s0} + assert all(query) == ~s{SELECT 1 IN (1,?1,3) FROM "schema" AS s0} query = Schema |> select([e], ^1 in [1, ^2, 3]) |> normalize - assert SQL.all(query) == ~s{SELECT ?1 IN (1,?2,3) FROM "schema" AS s0} + assert all(query) == ~s{SELECT ?1 IN (1,?2,3) FROM "schema" AS s0} query = Schema |> select([e], ^1 in ^[1, 2, 3]) |> normalize - assert SQL.all(query) == ~s{SELECT ?1 IN (?2,?3,?4) FROM "schema" AS s0} + assert all(query) == ~s{SELECT ?1 IN (?2,?3,?4) FROM "schema" AS s0} # query = Schema |> select([e], 1 in e.w) |> normalize - # assert SQL.all(query) == ~s{SELECT 1 = ANY(s0."w") FROM "schema" AS s0} + # assert all(query) == ~s{SELECT 1 = ANY(s0."w") FROM "schema" AS s0} # This assertion omitted because we can't support array values. query = Schema |> select([e], 1 in fragment("foo")) |> normalize - assert SQL.all(query) == ~s{SELECT 1 IN (foo) FROM "schema" AS s0} + assert all(query) == ~s{SELECT 1 IN (foo) FROM "schema" AS s0} end test "having" do query = Schema |> having([p], p.x == p.x) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 HAVING (s0."x" = s0."x")} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 HAVING (s0."x" = s0."x")} query = Schema |> having([p], p.x == p.x) |> having([p], p.y == p.y) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 HAVING (s0."x" = s0."x") AND (s0."y" = s0."y")} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 HAVING (s0."x" = s0."x") AND (s0."y" = s0."y")} end test "or_having" do query = Schema |> or_having([p], p.x == p.x) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 HAVING (s0."x" = s0."x")} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 HAVING (s0."x" = s0."x")} query = Schema |> or_having([p], p.x == p.x) |> or_having([p], p.y == p.y) |> select([], true) |> normalize - assert SQL.all(query) == ~s{SELECT 1 FROM "schema" AS s0 HAVING (s0."x" = s0."x") OR (s0."y" = s0."y")} + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 HAVING (s0."x" = s0."x") OR (s0."y" = s0."y")} end test "group by" do query = Schema |> group_by([r], r.x) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 GROUP BY s0."x"} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 GROUP BY s0."x"} query = Schema |> group_by([r], 2) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 GROUP BY 2} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 GROUP BY 2} query = Schema |> group_by([r], [r.x, r.y]) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 GROUP BY s0."x", s0."y"} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 GROUP BY s0."x", s0."y"} query = Schema |> group_by([r], []) |> select([r], r.x) |> normalize - assert SQL.all(query) == ~s{SELECT s0."x" FROM "schema" AS s0} + assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0} end test "arrays and sigils" do assert_raise ArgumentError, "Array values are not supported by SQLite", fn -> query = Schema |> select([], fragment("?", [1, 2, 3])) |> normalize - SQL.all(query) + all(query) end assert_raise ArgumentError, "Array values are not supported by SQLite", fn -> query = Schema |> select([], fragment("?", ~w(abc def))) |> normalize - SQL.all(query) + all(query) end end @@ -414,7 +431,7 @@ defmodule Sqlite.Ecto2.Test do ORDER BY ?10, s0."x" LIMIT ?11 OFFSET ?12 """ - assert SQL.all(query) == result + assert all(query) == result end test "fragments and types" do @@ -429,7 +446,7 @@ defmodule Sqlite.Ecto2.Test do "WHERE (extract(?1 from s0.\"start_time\") = ?2) " <> "AND (extract(?3 from s0.\"start_time\") = ?4)" - assert SQL.all(query) == String.trim(result) + assert all(query) == String.trim(result) end test "fragments allow ? to be escaped with backslash" do @@ -442,44 +459,44 @@ defmodule Sqlite.Ecto2.Test do "SELECT 1 FROM \"schema\" AS s0 " <> "WHERE (s0.\"start_time\" = \"query?\")" - assert SQL.all(query) == String.trim(result) + assert all(query) == String.trim(result) end ## *_all test "update all" do query = from(m in Schema, update: [set: [x: 0]]) |> normalize(:update_all) - assert SQL.update_all(query) == + assert update_all(query) == ~s{UPDATE "schema" SET "x" = 0} query = from(m in Schema, update: [set: [x: 0], inc: [y: 1, z: -3]]) |> normalize(:update_all) - assert SQL.update_all(query) == + assert update_all(query) == ~s{UPDATE "schema" SET "x" = 0, "y" = "schema"."y" + 1, "z" = "schema"."z" + -3} query = from(e in Schema, where: e.x == 123, update: [set: [x: 0]]) |> normalize(:update_all) - assert SQL.update_all(query) == + assert update_all(query) == ~s{UPDATE "schema" SET "x" = 0 WHERE ("schema"."x" = 123)} query = from(m in Schema, update: [set: [x: ^0]]) |> normalize(:update_all) - assert SQL.update_all(query) == + assert update_all(query) == ~s{UPDATE "schema" SET "x" = ?1} assert_raise ArgumentError, "JOINS are not supported on UPDATE statements by SQLite", fn -> query = Schema |> join(:inner, [p], q in Schema2, p.x == q.z) |> update([_], set: [x: 0]) |> normalize(:update_all) - SQL.update_all(query) + update_all(query) end assert_raise ArgumentError, "JOINS are not supported on UPDATE statements by SQLite", fn -> query = from(e in Schema, where: e.x == 123, update: [set: [x: 0]], join: q in Schema2, on: e.x == q.z) |> normalize(:update_all) - SQL.update_all(query) + update_all(query) end end test "update all with returning" do query = from(m in Schema, update: [set: [x: 0]]) |> select([m], m) |> normalize(:update_all) - assert SQL.update_all(query) == + assert update_all(query) == ~s{UPDATE "schema" SET "x" = 0 ;--RETURNING ON UPDATE "schema","id","x","y","z"} # diff SQLite syntax end @@ -487,98 +504,98 @@ defmodule Sqlite.Ecto2.Test do test "update all array ops" do assert_raise ArgumentError, "Array operations are not supported by SQLite", fn -> query = from(m in SchemaWithArray, update: [push: [w: 0]]) |> normalize(:update_all) - SQL.update_all(query) + update_all(query) end assert_raise ArgumentError, "Array operations are not supported by SQLite", fn -> query = from(m in SchemaWithArray, update: [pull: [w: 0]]) |> normalize(:update_all) - SQL.update_all(query) + update_all(query) end end test "update all with prefix" do # new don't know what to expect query = from(m in Schema, update: [set: [x: 0]]) |> normalize(:update_all) - assert SQL.update_all(%{query | prefix: "prefix"}) == + assert update_all(%{query | prefix: "prefix"}) == ~s{UPDATE "prefix"."schema" SET "x" = 0} end test "delete all" do query = Schema |> Queryable.to_query |> normalize - assert SQL.delete_all(query) == ~s{DELETE FROM "schema"} + assert delete_all(query) == ~s{DELETE FROM "schema"} query = from(e in Schema, where: e.x == 123) |> normalize - assert SQL.delete_all(query) == + assert delete_all(query) == ~s{DELETE FROM "schema" WHERE ("schema"."x" = 123)} assert_raise ArgumentError, "JOINS are not supported on DELETE statements by SQLite", fn -> query = Schema |> join(:inner, [p], q in Schema2, p.x == q.z) |> normalize - SQL.delete_all(query) + delete_all(query) end assert_raise ArgumentError, "JOINS are not supported on DELETE statements by SQLite", fn -> query = from(e in Schema, where: e.x == 123, join: q in Schema2, on: e.x == q.z) |> normalize - SQL.delete_all(query) + delete_all(query) end assert_raise ArgumentError, "JOINS are not supported on DELETE statements by SQLite", fn -> query = from(e in Schema, where: e.x == 123, join: assoc(e, :comments), join: assoc(e, :permalink)) |> normalize - SQL.delete_all(query) + delete_all(query) end end test "delete all with returning" do query = Schema |> Queryable.to_query |> select([m], m) |> normalize - assert SQL.delete_all(query) == ~s{DELETE FROM "schema" ;--RETURNING ON DELETE "schema","id","x","y","z"} + assert delete_all(query) == ~s{DELETE FROM "schema" ;--RETURNING ON DELETE "schema","id","x","y","z"} end test "delete all with prefix" do query = Schema |> Queryable.to_query |> normalize - assert SQL.delete_all(%{query | prefix: "prefix"}) == ~s{DELETE FROM "prefix"."schema"} + assert delete_all(%{query | prefix: "prefix"}) == ~s{DELETE FROM "prefix"."schema"} end ## Joins test "join" do query = Schema |> join(:inner, [p], q in Schema2, p.x == q.z) |> select([], true) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 INNER JOIN "schema2" AS s1 ON s0."x" = s1."z"} query = Schema |> join(:inner, [p], q in Schema2, p.x == q.z) |> join(:inner, [], Schema, true) |> select([], true) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 INNER JOIN "schema2" AS s1 ON s0."x" = s1."z" } <> ~s{INNER JOIN "schema" AS s2 ON 1} end test "join with nothing bound" do query = Schema |> join(:inner, [], q in Schema2, q.z == q.z) |> select([], true) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT 1 FROM "schema" AS s0 INNER JOIN "schema2" AS s1 ON s1."z" = s1."z"} end test "join without schema" do query = "posts" |> join(:inner, [p], q in "comments", p.x == q.z) |> select([], true) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT 1 FROM "posts" AS p0 INNER JOIN "comments" AS c1 ON p0."x" = c1."z"} end test "join with subquery" do posts = subquery("posts" |> where(title: ^"hello") |> select([r], %{x: r.x, y: r.y})) query = "comments" |> join(:inner, [c], p in subquery(posts), true) |> select([_, p], p.x) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT s1."x" FROM "comments" AS c0 } <> ~s{INNER JOIN (SELECT p0."x" AS "x", p0."y" AS "y" FROM "posts" AS p0 WHERE (p0."title" = ?1)) AS s1 ON 1} posts = subquery("posts" |> where(title: ^"hello") |> select([r], %{x: r.x, z: r.y})) query = "comments" |> join(:inner, [c], p in subquery(posts), true) |> select([_, p], p) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT s1."x", s1."z" FROM "comments" AS c0 } <> ~s{INNER JOIN (SELECT p0."x" AS "x", p0."y" AS "z" FROM "posts" AS p0 WHERE (p0."title" = ?1)) AS s1 ON 1} end test "join with prefix" do query = Schema |> join(:inner, [p], q in Schema2, p.x == q.z) |> select([], true) |> normalize - assert SQL.all(%{query | prefix: "prefix"}) == + assert all(%{query | prefix: "prefix"}) == ~s{SELECT 1 FROM "prefix"."schema" AS s0 INNER JOIN "prefix"."schema2" AS s1 ON s0."x" = s1."z"} end @@ -588,7 +605,7 @@ defmodule Sqlite.Ecto2.Test do |> select([p], {p.id, ^0}) |> where([p], p.id > 0 and p.id < ^100) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT s0."id", ?1 FROM "schema" AS s0 INNER JOIN } <> ~s{(SELECT * FROM schema2 AS s2 WHERE s2.id = s0."x" AND s2.field = ?2) AS f1 ON 1 } <> ~s{WHERE ((s0."id" > 0) AND (s0."id" < ?3))} @@ -599,7 +616,7 @@ defmodule Sqlite.Ecto2.Test do |> join(:inner, [p], q in fragment("SELECT * FROM schema2"), q.id == p.id) |> select([p], {p.id, ^0}) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT s0."id", ?1 FROM "schema" AS s0 INNER JOIN } <> ~s{(SELECT * FROM schema2) AS f1 ON f1."id" = s0."id"} end @@ -607,7 +624,7 @@ defmodule Sqlite.Ecto2.Test do test "join with query interpolation" do inner = Ecto.Queryable.to_query(Schema2) query = from(p in Schema, left_join: c in ^inner, select: {p.id, c.id}) |> normalize() - assert SQL.all(query) == + assert all(query) == "SELECT s0.\"id\", s1.\"id\" FROM \"schema\" AS s0 LEFT JOIN \"schema2\" AS s1 ON 1" end @@ -618,14 +635,14 @@ defmodule Sqlite.Ecto2.Test do |> select([p, q], {p.id, q.z}) |> where([p], p.id > 0 and p.id < ^100) |> normalize - SQL.all(query) + all(query) end 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() - SQL.all(query) + all(query) end end @@ -633,7 +650,7 @@ defmodule Sqlite.Ecto2.Test do query = from(p in Schema, join: c in Schema2, on: true) query = from(p in query, join: c in Schema2, on: true, select: {p.id, c.id}) query = normalize(query) - assert SQL.all(query) == + assert all(query) == "SELECT s0.\"id\", s2.\"id\" FROM \"schema\" AS s0 INNER JOIN \"schema2\" AS s1 ON 1 INNER JOIN \"schema2\" AS s2 ON 1" end @@ -641,7 +658,7 @@ defmodule Sqlite.Ecto2.Test do test "self join on subquery" do subquery = select(Schema, [r], %{x: r.x, y: r.y}) query = subquery |> join(:inner, [c], p in subquery(subquery), true) |> normalize - assert SQL.all(query) == + assert all(query) == ~s{SELECT s0."x", s0."y" FROM "schema" AS s0 INNER JOIN } <> ~s{(SELECT s0."x" AS "x", s0."y" AS "y" FROM "schema" AS s0) } <> ~s{AS s1 ON 1} @@ -651,7 +668,7 @@ defmodule Sqlite.Ecto2.Test do # test "self join on subquery with fragment" do # subquery = select(Schema, [r], %{string: fragment("downcase(?)", ^"string")}) # query = subquery |> join(:inner, [c], p in subquery(subquery), true) |> normalize - # assert SQL.all(query) == + # assert all(query) == # ~s{SELECT downcase(?1) FROM "schema" AS s0 INNER JOIN } <> # ~s{(SELECT downcase(?2) AS "string" FROM "schema" AS s0) } <> # ~s{AS s1 ON 1} @@ -665,7 +682,7 @@ defmodule Sqlite.Ecto2.Test do # |> where([a, b], a.x == ^111) # |> normalize # - # assert SQL.all(query) == + # assert all(query) == # ~s{SELECT ?1 FROM "schema" AS s0 INNER JOIN } <> # ~s{(SELECT ?2 AS "x", ?3 AS "w" FROM "schema" AS s0) AS s1 ON 1 } <> # ~s{WHERE (s0."x" = ?4)} @@ -676,111 +693,111 @@ defmodule Sqlite.Ecto2.Test do test "association join belongs_to" do query = Schema2 |> join(:inner, [c], p in assoc(c, :post)) |> select([], true) |> normalize - assert SQL.all(query) == + assert all(query) == "SELECT 1 FROM \"schema2\" AS s0 INNER JOIN \"schema\" AS s1 ON s1.\"x\" = s0.\"z\"" end test "association join has_many" do query = Schema |> join(:inner, [p], c in assoc(p, :comments)) |> select([], true) |> normalize - assert SQL.all(query) == + assert all(query) == "SELECT 1 FROM \"schema\" AS s0 INNER JOIN \"schema2\" AS s1 ON s1.\"z\" = s0.\"x\"" end test "association join has_one" do query = Schema |> join(:inner, [p], pp in assoc(p, :permalink)) |> select([], true) |> normalize - assert SQL.all(query) == + assert all(query) == "SELECT 1 FROM \"schema\" AS s0 INNER JOIN \"schema3\" AS s1 ON s1.\"id\" = s0.\"y\"" end # Schema based test "insert" do - query = SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {:raise, [], []}, [:id]) + query = insert(nil, "schema", [:x, :y], [[:x, :y]], {:raise, [], []}, [:id]) assert query == ~s{INSERT INTO "schema" ("x","y") VALUES (?1,?2) ;--RETURNING ON INSERT "schema","id"} assert_raise ArgumentError, "Cell-wise default values are not supported on INSERT statements by SQLite", fn -> - SQL.insert(nil, "schema", [:x, :y], [[:x, :y], [nil, :z]], {:raise, [], []}, [:id]) + insert(nil, "schema", [:x, :y], [[:x, :y], [nil, :z]], {:raise, [], []}, [:id]) end - query = SQL.insert(nil, "schema", [], [[]], {:raise, [], []}, [:id]) + query = insert(nil, "schema", [], [[]], {:raise, [], []}, [:id]) assert query == ~s{INSERT INTO "schema" DEFAULT VALUES ;--RETURNING ON INSERT "schema","id"} - query = SQL.insert(nil, "schema", [], [[]], {:raise, [], []}, []) + query = insert(nil, "schema", [], [[]], {:raise, [], []}, []) assert query == ~s{INSERT INTO "schema" DEFAULT VALUES} - query = SQL.insert("prefix", "schema", [], [[]], {:raise, [], []}, [:id]) + query = insert("prefix", "schema", [], [[]], {:raise, [], []}, [:id]) assert query == ~s{INSERT INTO "prefix"."schema" DEFAULT VALUES ;--RETURNING ON INSERT "prefix"."schema","id"} - query = SQL.insert("prefix", "schema", [], [[]], {:raise, [], []}, []) + query = insert("prefix", "schema", [], [[]], {:raise, [], []}, []) assert query == ~s{INSERT INTO "prefix"."schema" DEFAULT VALUES} end test "insert with on conflict" do - query = SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {:nothing, [], []}, []) + query = insert(nil, "schema", [:x, :y], [[:x, :y]], {:nothing, [], []}, []) assert query == ~s{INSERT OR IGNORE INTO "schema" ("x","y") VALUES (?1,?2)} assert_raise ArgumentError, "Upsert in SQLite must use on_conflict: :nothing", fn -> - SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {:nothing, [], [:x, :y]}, []) + insert(nil, "schema", [:x, :y], [[:x, :y]], {:nothing, [], [:x, :y]}, []) end assert_raise ArgumentError, "Upsert in SQLite must use on_conflict: :nothing", fn -> update = from("schema", update: [set: [z: "foo"]]) |> normalize(:update_all) - SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {update, [], [:x, :y]}, [:z]) + insert(nil, "schema", [:x, :y], [[:x, :y]], {update, [], [:x, :y]}, [:z]) end assert_raise ArgumentError, "Upsert in SQLite must use on_conflict: :nothing", fn -> update = from("schema", update: [set: [z: ^"foo"]], where: [w: true]) |> normalize(:update_all, 2) - SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {update, [], [:x, :y]}, [:z]) + insert(nil, "schema", [:x, :y], [[:x, :y]], {update, [], [:x, :y]}, [:z]) end assert_raise ArgumentError, "Upsert in SQLite must use on_conflict: :nothing", fn -> update = normalize(from("schema", update: [set: [z: "foo"]]), :update_all) - SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {update, [], [:x, :y]}, [:z]) + insert(nil, "schema", [:x, :y], [[:x, :y]], {update, [], [:x, :y]}, [:z]) end assert_raise ArgumentError, "Upsert in SQLite must use on_conflict: :nothing", fn -> update = normalize(from("schema", update: [set: [z: ^"foo"]], where: [w: true]), :update_all, 2) - SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {update, [], [:x, :y]}, [:z]) + insert(nil, "schema", [:x, :y], [[:x, :y]], {update, [], [:x, :y]}, [:z]) end # For :replace_all assert_raise ArgumentError, "Upsert in SQLite must use on_conflict: :nothing", fn -> - SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {:replace_all, [], [:id]}, []) + insert(nil, "schema", [:x, :y], [[:x, :y]], {:replace_all, [], [:id]}, []) end assert_raise ArgumentError, "Upsert in SQLite must use on_conflict: :nothing", fn -> - SQL.insert(nil, "schema", [:x, :y], [[:x, :y]], {:replace_all, [], []}, []) + insert(nil, "schema", [:x, :y], [[:x, :y]], {:replace_all, [], []}, []) end end test "update" do - query = SQL.update(nil, "schema", [:x, :y], [:id], []) + query = update(nil, "schema", [:x, :y], [:id], []) assert query == ~s{UPDATE "schema" SET "x" = ?1, "y" = ?2 WHERE "id" = ?3} - query = SQL.update(nil, "schema", [:x, :y], [:id], [:z]) + query = update(nil, "schema", [:x, :y], [:id], [:z]) assert query == ~s{UPDATE "schema" SET "x" = ?1, "y" = ?2 WHERE "id" = ?3 ;--RETURNING ON UPDATE "schema","z"} - query = SQL.update("prefix", "schema", [:x, :y], [:id], [:x, :z]) + query = update("prefix", "schema", [:x, :y], [:id], [:x, :z]) assert query == ~s{UPDATE "prefix"."schema" SET "x" = ?1, "y" = ?2 WHERE "id" = ?3 ;--RETURNING ON UPDATE "prefix"."schema","x","z"} - query = SQL.update("prefix", "schema", [:x, :y], [:id], []) + query = update("prefix", "schema", [:x, :y], [:id], []) assert query == ~s{UPDATE "prefix"."schema" SET "x" = ?1, "y" = ?2 WHERE "id" = ?3} end test "delete" do - query = SQL.delete(nil, "schema", [:x, :y], []) + query = delete(nil, "schema", [:x, :y], []) assert query == ~s{DELETE FROM "schema" WHERE "x" = ?1 AND "y" = ?2} - query = SQL.delete(nil, "schema", [:x, :y], [:z]) + query = delete(nil, "schema", [:x, :y], [:z]) assert query == ~s{DELETE FROM "schema" WHERE "x" = ?1 AND "y" = ?2 ;--RETURNING ON DELETE "schema","z"} - query = SQL.delete("prefix", "schema", [:x, :y], [:z]) + query = delete("prefix", "schema", [:x, :y], [:z]) assert query == ~s{DELETE FROM "prefix"."schema" WHERE "x" = ?1 AND "y" = ?2 ;--RETURNING ON DELETE "prefix"."schema","z"} - query = SQL.delete(nil, "schema", [:x, :y], []) + query = delete(nil, "schema", [:x, :y], []) assert query == ~s{DELETE FROM "schema" WHERE "x" = ?1 AND "y" = ?2} - query = SQL.delete("prefix", "schema", [:x, :y], []) + query = delete("prefix", "schema", [:x, :y], []) assert query == ~s{DELETE FROM "prefix"."schema" WHERE "x" = ?1 AND "y" = ?2} end @@ -1059,14 +1076,14 @@ defmodule Sqlite.Ecto2.Test do test "alter column errors for :modify column" do alter = {:alter, table(:posts), [{:modify, :price, :numeric, [precision: 8, scale: 2]}]} assert_raise ArgumentError, "ALTER COLUMN not supported by SQLite", fn -> - SQL.execute_ddl(alter) + execute_ddl(alter) end end test "alter column errors for :remove column" do alter = {:alter, table(:posts), [{:remove, :price, :numeric, [precision: 8, scale: 2]}]} assert_raise ArgumentError, "ALTER COLUMN not supported by SQLite", fn -> - SQL.execute_ddl(alter) + execute_ddl(alter) end end @@ -1087,7 +1104,7 @@ defmodule Sqlite.Ecto2.Test do create = {:create, index(:posts, ["lower(permalink)"], name: "posts$main")} assert execute_ddl(create) == - [~s|CREATE INDEX "posts$main" ON "posts" ((lower(permalink)))|] + [~s|CREATE INDEX "posts$main" ON "posts" (lower(permalink))|] end test "create index if not exists" do @@ -1103,7 +1120,7 @@ defmodule Sqlite.Ecto2.Test do create = {:create, index(:posts, ["lower(permalink)"], name: "posts$main", prefix: :foo)} assert execute_ddl(create) == - [~s|CREATE INDEX "posts$main" ON "foo"."posts" ((lower(permalink)))|] + [~s|CREATE INDEX "posts$main" ON "foo"."posts" (lower(permalink))|] end test "create index with comment" do @@ -1181,19 +1198,19 @@ defmodule Sqlite.Ecto2.Test do test "create check constraint" do create = {:create, constraint(:products, "price_must_be_positive", check: "price > 0")} assert_raise ArgumentError, "ALTER TABLE with constraints not supported by SQLite", fn -> - SQL.execute_ddl(create) + execute_ddl(create) end create = {:create, constraint(:products, "price_must_be_positive", check: "price > 0", prefix: "foo")} assert_raise ArgumentError, "ALTER TABLE with constraints not supported by SQLite", fn -> - SQL.execute_ddl(create) + execute_ddl(create) end end test "create exclusion constraint" do create = {:create, constraint(:products, "price_must_be_positive", exclude: ~s|gist (int4range("from", "to", '[]') WITH &&)|)} assert_raise ArgumentError, "ALTER TABLE with constraints not supported by SQLite", fn -> - SQL.execute_ddl(create) + execute_ddl(create) end end @@ -1207,12 +1224,12 @@ defmodule Sqlite.Ecto2.Test do test "drop constraint" do drop = {:drop, constraint(:products, "price_must_be_positive")} assert_raise ArgumentError, "ALTER TABLE with constraints not supported by SQLite", fn -> - SQL.execute_ddl(drop) + execute_ddl(drop) end drop = {:drop, constraint(:products, "price_must_be_positive", prefix: "foo")} assert_raise ArgumentError, "ALTER TABLE with constraints not supported by SQLite", fn -> - SQL.execute_ddl(drop) + execute_ddl(drop) end end @@ -1229,21 +1246,21 @@ defmodule Sqlite.Ecto2.Test do test "rename column" do rename = {:rename, table(:posts), :given_name, :first_name} assert_raise ArgumentError, "RENAME COLUMN not supported by SQLite", fn -> - SQL.execute_ddl(rename) + execute_ddl(rename) end end test "rename column in prefixed table" do rename = {:rename, table(:posts, prefix: :foo), :given_name, :first_name} assert_raise ArgumentError, "RENAME COLUMN not supported by SQLite", fn -> - SQL.execute_ddl(rename) + execute_ddl(rename) end end test "drop column errors" do alter = {:alter, table(:posts), [{:remove, :summary}]} assert_raise ArgumentError, "DROP COLUMN not supported by SQLite", fn -> - SQL.execute_ddl(alter) + execute_ddl(alter) end end @@ -1272,8 +1289,4 @@ defmodule Sqlite.Ecto2.Test do defp remove_newlines(string) do string |> String.trim |> String.replace("\n", " ") end - - defp execute_ddl(command) do - command |> SQL.execute_ddl() |> Enum.map(&IO.iodata_to_binary/1) - end end From 004215da81e14e71b5a9dc33949697662dee7f08 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 18:29:09 -0700 Subject: [PATCH 17/21] Restore test that was broken a few versions ago. --- test/sqlite_ecto_test.exs | 45 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/test/sqlite_ecto_test.exs b/test/sqlite_ecto_test.exs index e5a2489a..1741092a 100644 --- a/test/sqlite_ecto_test.exs +++ b/test/sqlite_ecto_test.exs @@ -664,29 +664,28 @@ defmodule Sqlite.Ecto2.Test do ~s{AS s1 ON 1} end - # Disabled for now. Also broken in corresponding Ecto test for Postgres adapter. - # test "self join on subquery with fragment" do - # subquery = select(Schema, [r], %{string: fragment("downcase(?)", ^"string")}) - # query = subquery |> join(:inner, [c], p in subquery(subquery), true) |> normalize - # assert all(query) == - # ~s{SELECT downcase(?1) FROM "schema" AS s0 INNER JOIN } <> - # ~s{(SELECT downcase(?2) AS "string" FROM "schema" AS s0) } <> - # ~s{AS s1 ON 1} - # end - # - # test "join on subquery with simple select" do - # subquery = select(Schema, [r], %{x: ^999, w: ^888}) - # query = Schema - # |> select([r], %{y: ^666}) - # |> join(:inner, [c], p in subquery(subquery), true) - # |> where([a, b], a.x == ^111) - # |> normalize - # - # assert all(query) == - # ~s{SELECT ?1 FROM "schema" AS s0 INNER JOIN } <> - # ~s{(SELECT ?2 AS "x", ?3 AS "w" FROM "schema" AS s0) AS s1 ON 1 } <> - # ~s{WHERE (s0."x" = ?4)} - # end + test "self join on subquery with fragment" do + subquery = select(Schema, [r], %{string: fragment("downcase(?)", ^"string")}) + query = subquery |> join(:inner, [c], p in subquery(subquery), true) |> normalize + assert all(query) == + ~s{SELECT downcase(?1) FROM "schema" AS s0 INNER JOIN } <> + ~s{(SELECT downcase(?2) AS "string" FROM "schema" AS s0) } <> + ~s{AS s1 ON 1} + end + + test "join on subquery with simple select" do + subquery = select(Schema, [r], %{x: ^999, w: ^888}) + query = Schema + |> select([r], %{y: ^666}) + |> join(:inner, [c], p in subquery(subquery), true) + |> where([a, b], a.x == ^111) + |> normalize + + assert all(query) == + ~s{SELECT ?1 FROM "schema" AS s0 INNER JOIN } <> + ~s{(SELECT ?2 AS "x", ?3 AS "w" FROM "schema" AS s0) AS s1 ON 1 } <> + ~s{WHERE (s0."x" = ?4)} + end end ## Associations From bb965d1656febce690b2ef6379ff923364630cd3 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 20:41:22 -0700 Subject: [PATCH 18/21] Add decoder for float type. Sadly, we now have to punt on Decimal support. There's really no way to store precision accurately. --- integration/sqlite/test_helper.exs | 3 ++- lib/sqlite_ecto.ex | 4 ++++ mix.exs | 2 +- mix.lock | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/integration/sqlite/test_helper.exs b/integration/sqlite/test_helper.exs index 959fef48..177a52c4 100644 --- a/integration/sqlite/test_helper.exs +++ b/integration/sqlite/test_helper.exs @@ -20,7 +20,8 @@ ExUnit.start exclude: [:array_type, :map_boolean_in_subquery, :upsert_all, :with_conflict_target, - :without_conflict_target] + :without_conflict_target, + :decimal_type] # Configure Ecto for support and tests Application.put_env(:ecto, :primary_key_type, :id) diff --git a/lib/sqlite_ecto.ex b/lib/sqlite_ecto.ex index 64cd7259..17bbe1f4 100644 --- a/lib/sqlite_ecto.ex +++ b/lib/sqlite_ecto.ex @@ -51,6 +51,7 @@ defmodule Sqlite.Ecto2 do do: [&json_decode/1, &Ecto.Adapters.SQL.load_embed(type, &1)] def loaders(:map, type), do: [&json_decode/1, type] def loaders({:map, _}, type), do: [&json_decode/1, type] + def loaders(:float, type), do: [&float_decode/1, type] def loaders(_primitive, type), do: [type] defp bool_decode(0), do: {:ok, false} @@ -81,6 +82,9 @@ defmodule Sqlite.Ecto2 do defp json_decode(x), do: {:ok, x} + defp float_decode(x) when is_integer(x), do: {:ok, x / 1} + defp float_decode(x), do: {:ok, x} + def dumpers(:binary, type), do: [type, &blob_encode/1] def dumpers(:binary_id, type), do: [type, Ecto.UUID] def dumpers(:boolean, type), do: [type, &bool_encode/1] diff --git a/mix.exs b/mix.exs index ea5b0182..6af1b925 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.16", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "0b12f8f8ff7f1e3259fe6302e30dca85eb8b21c1"}, + {:ecto, github: "elixir-ecto/ecto", ref: "8370287445932298ec3e92d929112301b28aabd9"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index dc9fc564..1d1f9e30 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "0b12f8f8ff7f1e3259fe6302e30dca85eb8b21c1", [ref: "0b12f8f8ff7f1e3259fe6302e30dca85eb8b21c1"]}, + "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "8370287445932298ec3e92d929112301b28aabd9", [ref: "8370287445932298ec3e92d929112301b28aabd9"]}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, From 220b3e8a1211645e98ef108b45d5f7194af2461b Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 21:02:39 -0700 Subject: [PATCH 19/21] Switch back to depending on regular Ecto releases. --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 6af1b925..f0a67179 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule Sqlite.Ecto2.Mixfile do {:dogma, "~> 0.1", only: :dev}, {:esqlite, "~> 0.2.3"}, {:ex_doc, "~> 0.16", only: :dev}, - {:ecto, github: "elixir-ecto/ecto", ref: "8370287445932298ec3e92d929112301b28aabd9"}, + {:ecto, "~> 2.2.0"}, {:poison, "~> 2.2 or ~> 3.0", optional: true}, {:postgrex, "~> 0.13.0", optional: true}, {:sbroker, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index 1d1f9e30..4f8f721d 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"}, - "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "8370287445932298ec3e92d929112301b28aabd9", [ref: "8370287445932298ec3e92d929112301b28aabd9"]}, + "ecto": {:hex, :ecto, "2.2.1", "ccc6fd304f9bb785f2c3cfd0ee8da6bad6544ab12ca5f7162b20a743d938417c", [], [{: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"}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, From 3d0e6ef48baa222667f89d968c13504697063f44 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 27 Aug 2017 21:09:15 -0700 Subject: [PATCH 20/21] Prepare version 2.2.0 release. --- CHANGELOG.md | 99 +++++----------------------------------------------- mix.exs | 2 +- 2 files changed, 10 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f208bd7..d74f08f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,97 +1,16 @@ -# Changelog for v2.0 +# Changelog for v2.2.x Series -This is a major rewrite of the previously-existing [`sqlite_ecto`](https://github.com/jazzyb/sqlite_ecto) that adds support for Ecto 2.1+. +## v2.2.0 +_28 August 2017_ -## v2.0.2 - -_12 August 2017_ - -* Update for Elixir 1.5.1. (Stop using a now-deprecated API; otherwise no significant changes.) - - -## v2.0.1 - -_7 August 2017_ - -* Formally announce availability. -* Fix a few README and CHANGELOG issues. - - -## v2.0.0 - -_6 August 2017_ - -* Fix a few documentation errors. - - -## v2.0.0-dev.8 - -_11 June 2017_ - -* Improve README content a bit. -* Make db_connection a hard dependency. (Fixes #174.) -* Update references to several libraries. - - -## v2.0.0-dev.7 - -_06 May 2017_ - -* Improve test coverage (now 98%). -* Add Dogma to CI build infrastructure to help enforce code format consistency. -* Remove `Sqlite.DbConnection` module in favor of directly calling `DbConnection` itself. - - -## v2.0.0-dev.6 - -_03 May 2017_ - -* Fix error messages that referred to PostgreSQL instead of SQLite. -* Improve test coverage (now 91%). -* Fix shell script issues flagged by Ebert. -* Clean up and simplify implementation of `Sqlite.DbConnection.Protocol`. - - -## v2.0.0-dev.5 - -_30 April 2017_ - -* Use iodata lists as much as possible during query generation. -* Switch to numeric placeholders across the board. -* Bring sqlite_ecto_test.exs up to date with corresponding postgres_test.exs from Ecto. - - -## v2.0.0-dev.4 - -_17 April 2017_ - -* Port documentation from v1 `sqlite_ecto` repo to this repo. (Thank you, @taufiqkh!) -* Enable automated code review by Ebert. Fix some of the issues it flagged. - - -## v2.0.0-dev.3 - -_11 April 2017_ - -* Requires sqlitex version 1.3.2 which includes an important bug fix (https://github.com/mmmries/sqlitex/pull/59). - - -## v2.0.0-dev.2 - -_26 March 2017_ - -* **BREAKING CHANGE:** Use the name `Sqlite.Ecto2` consistently in API names. Discontinue use of name `Sqlite.Ecto` (without the `2`) -* Ensure db_connection app is started before relying on it. - - -## v2.0.0-dev.1 - -_21 March 2017_ - -Initial public release of version 2.0 (alpha quality). +* Update to support Ecto 2.2.x. (Aligned version numbers to match Ecto versioning series.) +* Drop support for Elixir 1.3.x. New minimum version is 1.4.0. +* Drop support for OTP 18.0. New minimum version is 18.2. +* Decimal value support, while still present in the library, is no longer officially supported. ## Previous versions -* See the CHANGELOG.md [for the v1.x series](https://github.com/jazzyb/sqlite_ecto/blob/master/CHANGELOG.md) +* [v2.0.x series](https://github.com/scouten/sqlite_ecto2/blob/v2.0/CHANGELOG.md) +* [v1.x series](https://github.com/jazzyb/sqlite_ecto/blob/master/CHANGELOG.md) diff --git a/mix.exs b/mix.exs index f0a67179..aa17f998 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule Sqlite.Ecto2.Mixfile do def project do [app: :sqlite_ecto2, - version: "2.0.2", + version: "2.2.0", name: "Sqlite.Ecto2", elixir: "~> 1.4", elixirc_options: [warnings_as_errors: true], From 12bb7a6275e9e3648f348a4943d68ca6ca1eaf0b Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Mon, 28 Aug 2017 11:47:45 -0700 Subject: [PATCH 21/21] Add note about Ecto 2.x version compatibility. This version only works with Ecto 2.2.x. I tried it with the latest 2.1.x release and it was broken (relying on APIs that don't exist in that series). --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 80c7dfdb..f5465251 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,23 @@ # sqlite_ecto2 -`sqlite_ecto2` is an Ecto 2.x adapter that allows you to create and maintain SQLite3 databases. +`sqlite_ecto2` is an Ecto 2.2.x adapter that allows you to create and maintain SQLite3 databases. Read [the tutorial](./docs/tutorial.md) for a detailed example of how to setup and use a SQLite repo with Ecto, or just check-out the CliffsNotes in the sections below if you want to get started quickly. +## Ecto Version Compatibility + +**IMPORTANT:** This release will _only_ work with Ecto 2.2.x. If you need compatibility with older versions of Ecto, please see: + +* Ecto 2.1.x -> [`sqlite_ecto2` 2.0.x series](https://github.com/scouten/sqlite_ecto2/tree/v2.0) +* Ecto 1.x -> [`sqlite_ecto` v1.x series](https://github.com/jazzyb/sqlite_ecto) + + ## When to Use `sqlite_ecto2` *(and when not to use it ...)* -If, for some reason, you still need to use Ecto 1.x, please look at [sqlite_ecto](https://github.com/jazzyb/sqlite_ecto), on which this project is based. - I strongly recommend reading [Appropriate Uses for SQLite](https://sqlite.org/whentouse.html) on the SQLite site itself. All of the considerations mentioned there apply to this library as well. I will add one more: If there is *any* potential that more than one server node will need to write directly to the database at once (as often happens when using Elixir in a clustered environment), **do not use** `sqlite_ecto2`. Remember that there is no separate database process in this configuration, so each of your cluster nodes would be writing to its **own** copy of the database without any synchronization. You probably don't want that. Look for a true client/server database (Postgres, MySQL, or similar) in that case. SQLite's sweet spot is single-machine deployments (embedded, desktop, etc.).