diff --git a/lib/moebius/query.ex b/lib/moebius/query.ex index 74d72de..a404c06 100644 --- a/lib/moebius/query.ex +++ b/lib/moebius/query.ex @@ -433,11 +433,11 @@ defmodule Moebius.Query do vals = Keyword.values(criteria) first_available_param = length(cmd.params) + 1 + {cols, _col_count} = - Enum.map_reduce(cols, first_available_param, - fn col, acc -> - {"#{col} = $#{acc}", acc + 1} - end) + Enum.map_reduce(cols, first_available_param, fn col, acc -> + {"#{col} = $#{acc}", acc + 1} + end) params = cmd.params ++ vals columns = Enum.join(cols, ", ") diff --git a/test/moebius/update_test.exs b/test/moebius/update_test.exs index 3646cdc..79d6c1a 100644 --- a/test/moebius/update_test.exs +++ b/test/moebius/update_test.exs @@ -43,9 +43,9 @@ defmodule Moebius.UpdateTest do assert cmd.params == ["test", "ox@test.com"] end - test "basic update with 'in' filter" do names = ["Super", "Mike"] + cmd = db(:users) |> filter(:first, in: names) @@ -56,19 +56,17 @@ defmodule Moebius.UpdateTest do assert cmd.params == names ++ [["newrole"]] end - test "basic update with '>' filter" do cmd = db(:users) |> filter(:order_count, gt: 5) |> update(roles: ["newrole"]) + assert cmd.sql == "update users set roles = $2 where order_count > $1 returning *;" assert length(cmd.params) == 2 assert cmd.params == [5, ["newrole"]] end - - # TODO: Move this to date tests # test "it actually works" do