Skip to content

Commit 5e27808

Browse files
committed
Upgrade to use ecto 2.1 instead of 2.0
1 parent 7e97991 commit 5e27808

5 files changed

Lines changed: 26 additions & 24 deletions

File tree

lib/mongo_ecto.ex

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,14 @@ defmodule Mongo.Ecto do
426426
end
427427

428428
@doc false
429-
def loaders(:time, type), do: [&load_time/1, type]
430-
def loaders(:date, type), do: [&load_date/1, type]
431-
def loaders(:datetime, type), do: [&load_datetime/1, type]
432-
def loaders(:binary_id, type), do: [&load_objectid/1, type]
433-
def loaders(:uuid, type), do: [&load_binary/1, type]
434-
def loaders(:binary, type), do: [&load_binary/1, type]
435-
def loaders(_base, type), do: [type]
429+
def loaders(:time, type), do: [&load_time/1, type]
430+
def loaders(:date, type), do: [&load_date/1, type]
431+
def loaders(:utc_datetime, type), do: [&load_datetime/1, type]
432+
def loaders(:naive_datetime, type), do: [&load_datetime/1, type]
433+
def loaders(:binary_id, type), do: [&load_objectid/1, type]
434+
def loaders(:uuid, type), do: [&load_binary/1, type]
435+
def loaders(:binary, type), do: [&load_binary/1, type]
436+
def loaders(_base, type), do: [type]
436437

437438
defp load_time(%BSON.DateTime{} = time) do
438439
{{_,_,_}, time} = BSON.DateTime.to_datetime(time)
@@ -469,13 +470,14 @@ defmodule Mongo.Ecto do
469470
defp load_objectid(_), do: :error
470471

471472
@doc false
472-
def dumpers(:time, type), do: [type, &dump_time/1]
473-
def dumpers(:date, type), do: [type, &dump_date/1]
474-
def dumpers(:datetime, type), do: [type, &dump_datetime/1]
475-
def dumpers(:binary_id, type), do: [type, &dump_objectid/1]
476-
def dumpers(:uuid, type), do: [type, &dump_binary(&1, :uuid)]
477-
def dumpers(:binary, type), do: [type, &dump_binary(&1, :generic)]
478-
def dumpers(_base, type), do: [type]
473+
def dumpers(:time, type), do: [type, &dump_time/1]
474+
def dumpers(:date, type), do: [type, &dump_date/1]
475+
def dumpers(:utc_datetime, type), do: [type, &dump_datetime/1]
476+
def dumpers(:naive_datetime, type), do: [type, &dump_datetime/1]
477+
def dumpers(:binary_id, type), do: [type, &dump_objectid/1]
478+
def dumpers(:uuid, type), do: [type, &dump_binary(&1, :uuid)]
479+
def dumpers(:binary, type), do: [type, &dump_binary(&1, :generic)]
480+
def dumpers(_base, type), do: [type]
479481

480482
defp dump_time({_, _, _, _} = time),
481483
do: {:ok, BSON.DateTime.from_datetime({{0, 0, 0}, time})}
@@ -537,13 +539,13 @@ defmodule Mongo.Ecto do
537539
end
538540

539541
@doc false
540-
def insert(_repo, meta, _params, [_|_] = returning, _opts) do
542+
def insert(_repo, meta, _params, _on_conflict, [_|_] = returning, _opts) do
541543
raise ArgumentError,
542544
"MongoDB adapter does not support :read_after_writes in models. " <>
543545
"The following fields in #{inspect meta.schema} are tagged as such: #{inspect returning}"
544546
end
545547

546-
def insert(repo, meta, params, [], opts) do
548+
def insert(repo, meta, params, _, [], opts) do
547549
normalized = NormalizedQuery.insert(meta, params)
548550

549551
case Connection.insert(repo, normalized, opts) do
@@ -554,7 +556,7 @@ defmodule Mongo.Ecto do
554556
end
555557
end
556558

557-
def insert_all(repo, meta, fields, params, returning, opts) do
559+
def insert_all(repo, meta, fields, params, _, returning, opts) do
558560
normalized = NormalizedQuery.insert(meta, params)
559561

560562
case Connection.insert_all(repo, normalized, opts) do

lib/mongo_ecto/normalized_query.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ defmodule Mongo.Ecto.NormalizedQuery do
225225

226226
defp query(%Query{wheres: wheres} = query, params, {_coll, _model, pk}) do
227227
wheres
228-
|> Enum.map(fn %Query.QueryExpr{expr: expr} ->
228+
|> Enum.map(fn %Query.BooleanExpr{expr: expr} ->
229229
pair(expr, params, pk, query, "where clause")
230230
end)
231231
|> :lists.flatten

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule Mongo.Ecto.Mixfile do
2121
defp deps do
2222
[
2323
{:mongodb, "~> 0.2.0"},
24-
{:ecto, "~> 2.0.0"},
24+
{:ecto, "~> 2.1.0"},
2525
{:dialyze, "~> 0.2.0", only: :dev},
2626
{:excoveralls, "~> 0.5", only: :test},
2727
{:inch_ex, "~> 0.5", only: :docs},

mix.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
%{"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []},
22
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []},
3-
"db_connection": {:hex, :db_connection, "1.1.0", "b2b88db6d7d12f99997b584d09fad98e560b817a20dab6a526830e339f54cdb3", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
3+
"db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
44
"decimal": {:hex, :decimal, "1.3.1", "157b3cedb2bfcb5359372a7766dd7a41091ad34578296e951f58a946fcab49c6", [:mix], []},
55
"dialyze": {:hex, :dialyze, "0.2.1", "9fb71767f96649020d769db7cbd7290059daff23707d6e851e206b1fdfa92f9d", [:mix], []},
66
"earmark": {:hex, :earmark, "1.1.1", "433136b7f2e99cde88b745b3a0cfc3fbc81fe58b918a09b40fce7f00db4d8187", [:mix], []},
7-
"ecto": {:hex, :ecto, "2.0.6", "9dcbf819c2a77f67a66b83739b7fcc00b71aaf6c100016db4f798930fa4cfd47", [:mix], [{:db_connection, "~> 1.0", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.1.2 or ~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.12.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}]},
7+
"ecto": {:hex, :ecto, "2.1.4", "d1ba932813ec0e0d9db481ef2c17777f1cefb11fc90fa7c142ff354972dfba7e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
88
"ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
99
"excoveralls": {:hex, :excoveralls, "0.6.2", "0e993d096f1fbb6e70a3daced5c89aac066bda6bce57829622aa2d1e2b338cfb", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
1010
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
@@ -15,6 +15,6 @@
1515
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
1616
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
1717
"mongodb": {:hex, :mongodb, "0.2.0", "95f85074534bb0a65c4983995903a458e36d0b096f62c1bbdd56bc196f48cf80", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0", [hex: :db_connection, optional: false]}]},
18-
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []},
18+
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
1919
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
2020
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}}

test/mongo_ecto/normalized_query_new_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ defmodule Mongo.Ecto.NormalizedQueryNewTest do
4444
end
4545

4646
defp normalize(query, operation \\ :all) do
47-
{query, params, _key} = Ecto.Query.Planner.prepare(query, operation, Mongo.Ecto)
48-
query = Ecto.Query.Planner.normalize(query, operation, Mongo.Ecto)
47+
{query, params, _key} = Ecto.Query.Planner.prepare(query, operation, Mongo.Ecto, 0)
48+
query = Ecto.Query.Planner.normalize(query, operation, Mongo.Ecto, 0)
4949
apply(Mongo.Ecto.NormalizedQuery, operation, [query, params])
5050
end
5151

0 commit comments

Comments
 (0)