Skip to content

Commit ca7c7f5

Browse files
committed
Rename ignore_errors to ignore to stay closer to the database definition
1 parent af90644 commit ca7c7f5

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

integration_test/myxql/upsert_all_test.exs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ defmodule Ecto.Integration.UpsertAllTest do
1919
assert TestRepo.insert_all(Post, [post], on_conflict: :nothing) == {1, nil}
2020
end
2121

22-
test "insert_mode: :ignore_errors" do
22+
test "insert_mode: :ignore" do
2323
post = [title: "first", uuid: "6fa459ea-ee8a-3ca4-894e-db77e160355e"]
2424
# First insert succeeds - 1 row inserted
2525
assert TestRepo.insert_all(Post, [post],
2626
on_conflict: :nothing,
27-
insert_mode: :ignore_errors
27+
insert_mode: :ignore
2828
) == {1, nil}
2929

3030
# Second insert is ignored due to duplicate - 0 rows inserted (INSERT IGNORE behavior)
3131
assert TestRepo.insert_all(Post, [post],
3232
on_conflict: :nothing,
33-
insert_mode: :ignore_errors
33+
insert_mode: :ignore
3434
) == {0, nil}
3535
end
3636

37-
test "insert_mode: :ignore_errors with mixed records (some conflicts, some new)" do
37+
test "insert_mode: :ignore with mixed records (some conflicts, some new)" do
3838
# Insert an existing post
3939
existing_uuid = "6fa459ea-ee8a-3ca4-894e-db77e160355e"
4040
existing_post = [title: "existing", uuid: existing_uuid]
4141

4242
assert TestRepo.insert_all(Post, [existing_post],
4343
on_conflict: :nothing,
44-
insert_mode: :ignore_errors
44+
insert_mode: :ignore
4545
) == {1, nil}
4646

4747
# Now insert a batch with one duplicate and two new records
@@ -57,7 +57,7 @@ defmodule Ecto.Integration.UpsertAllTest do
5757
# With INSERT IGNORE, only 2 rows should be inserted (the non-duplicates)
5858
assert TestRepo.insert_all(Post, posts,
5959
on_conflict: :nothing,
60-
insert_mode: :ignore_errors
60+
insert_mode: :ignore
6161
) == {2, nil}
6262

6363
# Verify the data - should have 3 posts total (1 existing + 2 new)
@@ -72,15 +72,15 @@ defmodule Ecto.Integration.UpsertAllTest do
7272
assert TestRepo.exists?(from p in Post, where: p.uuid == ^new_uuid2)
7373
end
7474

75-
test "insert_mode: :ignore_errors with all duplicates" do
75+
test "insert_mode: :ignore with all duplicates" do
7676
# Insert initial posts
7777
uuid1 = "1fa459ea-ee8a-3ca4-894e-db77e160355e"
7878
uuid2 = "2fa459ea-ee8a-3ca4-894e-db77e160355e"
7979
initial_posts = [[title: "first", uuid: uuid1], [title: "second", uuid: uuid2]]
8080

8181
assert TestRepo.insert_all(Post, initial_posts,
8282
on_conflict: :nothing,
83-
insert_mode: :ignore_errors
83+
insert_mode: :ignore
8484
) == {2, nil}
8585

8686
# Try to insert all duplicates
@@ -89,7 +89,7 @@ defmodule Ecto.Integration.UpsertAllTest do
8989
# All are duplicates, so 0 rows inserted
9090
assert TestRepo.insert_all(Post, duplicate_posts,
9191
on_conflict: :nothing,
92-
insert_mode: :ignore_errors
92+
insert_mode: :ignore
9393
) == {0, nil}
9494

9595
# Verify count unchanged
@@ -102,18 +102,21 @@ defmodule Ecto.Integration.UpsertAllTest do
102102
{1, nil} = TestRepo.insert_all(Post, [post], on_conflict: on_conflict)
103103

104104
assert TestRepo.insert_all(Post, [post], on_conflict: on_conflict) ==
105-
{2, nil}
105+
{2, nil}
106+
106107
assert TestRepo.all(from p in Post, select: p.title) == ["second"]
107108
end
108109

109110
test "on conflict query and conflict target" do
110111
on_conflict = from Post, update: [set: [title: "second"]]
111112
post = [title: "first", uuid: "6fa459ea-ee8a-3ca4-894e-db77e160355e"]
113+
112114
assert TestRepo.insert_all(Post, [post], on_conflict: on_conflict) ==
113-
{1, nil}
115+
{1, nil}
114116

115117
assert TestRepo.insert_all(Post, [post], on_conflict: on_conflict) ==
116-
{2, nil}
118+
{2, nil}
119+
117120
assert TestRepo.all(from p in Post, select: p.title) == ["second"]
118121
end
119122
end

lib/ecto/adapters/myxql.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ defmodule Ecto.Adapters.MyXQL do
106106
### Insert Mode
107107
108108
The `:insert_mode` option controls the type of INSERT statement generated.
109-
When set to `:ignore_errors`, the adapter uses MySQL's `INSERT IGNORE`
109+
When set to `:ignore`, the adapter uses MySQL's `INSERT IGNORE`
110110
syntax:
111111
112-
Repo.insert_all(Post, posts, insert_mode: :ignore_errors)
112+
Repo.insert_all(Post, posts, insert_mode: :ignore)
113113
114114
With `INSERT IGNORE`, MySQL silently ignores errors that would normally
115115
cause the statement to fail, such as duplicate key violations and certain
@@ -126,11 +126,11 @@ defmodule Ecto.Adapters.MyXQL do
126126
the row was actually inserted or ignored.
127127
128128
If you need accurate row counts (0 when ignored, 1 when inserted) at the expense of error handling,
129-
you can combine `on_conflict: :nothing` with [`insert_mode: :ignore_errors`](#module-insert-mode):
129+
you can combine `on_conflict: :nothing` with [`insert_mode: :ignore`](#module-insert-mode):
130130
131131
Repo.insert_all(Post, posts,
132132
on_conflict: :nothing,
133-
insert_mode: :ignore_errors)
133+
insert_mode: :ignore)
134134
135135
When both options are used together, `INSERT IGNORE` handles the conflict
136136
resolution and the `ON DUPLICATE KEY UPDATE` clause is omitted.
@@ -147,7 +147,7 @@ defmodule Ecto.Adapters.MyXQL do
147147
```elixir
148148
Repo.insert_all(Post, posts,
149149
on_conflict: :nothing,
150-
insert_mode: :ignore_errors)
150+
insert_mode: :ignore)
151151
152152
# SQL: INSERT IGNORE INTO `posts` (`title`, `uuid`) VALUES (?,?)
153153
```
@@ -382,9 +382,9 @@ defmodule Ecto.Adapters.MyXQL do
382382

383383
case Ecto.Adapters.SQL.query(adapter_meta, sql, values ++ query_params, opts) do
384384
{:ok, %{num_rows: 0}} ->
385-
# With INSERT IGNORE (insert_mode: :ignore_errors), 0 rows means the row
385+
# With INSERT IGNORE (insert_mode: :ignore), 0 rows means the row
386386
# was ignored due to a conflict, which is expected behavior
387-
if opts[:insert_mode] == :ignore_errors do
387+
if opts[:insert_mode] == :ignore do
388388
{:ok, []}
389389
else
390390
raise "insert operation failed to insert any row in the database. " <>

lib/ecto/adapters/myxql/connection.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ if Code.ensure_loaded?(MyXQL) do
204204
error!(nil, ":placeholders is not supported by MySQL")
205205
end
206206

207-
# INSERT IGNORE when insert_mode: :ignore_errors is passed, independent of on_conflict
208-
defp insert_keyword(:ignore_errors) do
207+
# INSERT IGNORE when insert_mode: :ignore is passed, independent of on_conflict
208+
defp insert_keyword(:ignore) do
209209
"INSERT IGNORE INTO "
210210
end
211211

@@ -221,10 +221,10 @@ if Code.ensure_loaded?(MyXQL) do
221221
[]
222222
end
223223

224-
# When insert_mode: :ignore_errors is used with on_conflict: :nothing,
224+
# When insert_mode: :ignore is used with on_conflict: :nothing,
225225
# INSERT IGNORE already handles conflicts - no ON DUPLICATE KEY UPDATE needed
226226
defp on_conflict({:nothing, _, []}, [field | _], opts) do
227-
if Keyword.get(opts, :insert_mode) == :ignore_errors do
227+
if Keyword.get(opts, :insert_mode) == :ignore do
228228
[]
229229
else
230230
# Default :nothing without INSERT IGNORE - uses workaround to simulate "do nothing" behavior

test/ecto/adapters/myxql_test.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,8 +1500,7 @@ defmodule Ecto.Adapters.MyXQLTest do
15001500
end
15011501
end
15021502

1503-
test "insert with insert_mode: :ignore_errors" do
1504-
# INSERT IGNORE via insert_mode: :ignore_errors option
1503+
test "insert with insert_mode: :ignore" do
15051504
query =
15061505
insert(
15071506
nil,
@@ -1510,7 +1509,7 @@ defmodule Ecto.Adapters.MyXQLTest do
15101509
[[:x, :y]],
15111510
{:nothing, [], []},
15121511
[],
1513-
insert_mode: :ignore_errors
1512+
insert_mode: :ignore
15141513
)
15151514

15161515
assert query == ~s{INSERT IGNORE INTO `schema` (`x`,`y`) VALUES (?,?)}

0 commit comments

Comments
 (0)