Skip to content

Commit 7aba2e4

Browse files
wrap_in_transaction
1 parent 4be0d9f commit 7aba2e4

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

integration_test/myxql/explain_test.exs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule Ecto.Integration.ExplainTest do
1010
explain = TestRepo.explain(:all, from(p in Post, where: p.title == "title"), timeout: 20000)
1111

1212
assert explain =~
13-
"| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |"
13+
"| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |"
1414

1515
assert explain =~ "p0"
1616
assert explain =~ "SIMPLE"
@@ -24,7 +24,9 @@ defmodule Ecto.Integration.ExplainTest do
2424
end
2525

2626
test "update" do
27-
explain = TestRepo.explain(:update_all, from(p in Post, update: [set: [title: "new title"]]))
27+
explain =
28+
TestRepo.explain(:update_all, from(p in Post, update: [set: [title: "new title"]]))
29+
2830
assert explain =~ "UPDATE"
2931
assert explain =~ "p0"
3032
end
@@ -37,7 +39,7 @@ defmodule Ecto.Integration.ExplainTest do
3739

3840
test "map format" do
3941
[explain] = TestRepo.explain(:all, Post, format: :map)
40-
keys = explain["query_block"] |> Map.keys
42+
keys = explain["query_block"] |> Map.keys()
4143
assert Enum.member?(keys, "cost_info")
4244
assert Enum.member?(keys, "select_id")
4345
assert Enum.member?(keys, "table")
@@ -46,7 +48,7 @@ defmodule Ecto.Integration.ExplainTest do
4648
test "explain without rolling back" do
4749
{:ok, {:ok, explain}} =
4850
TestRepo.transaction(fn ->
49-
TestRepo.explain(:delete_all, Post, rollback: false, timeout: 20000)
51+
TestRepo.explain(:delete_all, Post, wrap_in_transaction: false, timeout: 20000)
5052
end)
5153

5254
assert explain =~ "DELETE"

integration_test/pg/explain_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ defmodule Ecto.Integration.ExplainTest do
8888

8989
{:ok, {:ok, explain}} =
9090
TestRepo.transaction(fn ->
91-
TestRepo.explain(:delete_all, Post, analyze: true, rollback: false, timeout: 20000)
91+
TestRepo.explain(:delete_all, Post,
92+
analyze: true,
93+
wrap_in_transaction: false,
94+
timeout: 20000
95+
)
9296
end)
9397

9498
assert explain =~ "Delete on posts p0"

integration_test/tds/explain_test.exs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ defmodule Ecto.Integration.ExplainTest do
77

88
describe "explain" do
99
test "select" do
10-
explain = TestRepo.explain(:all, from(p in Post, where: p.title == "explain_test", limit: 1))
10+
explain =
11+
TestRepo.explain(:all, from(p in Post, where: p.title == "explain_test", limit: 1))
12+
1113
assert explain =~ "| Rows | Executes |"
1214
assert explain =~ "| Parallel | EstimateExecutions |"
1315
assert explain =~ "SELECT TOP(1)"
@@ -21,7 +23,9 @@ defmodule Ecto.Integration.ExplainTest do
2123
end
2224

2325
test "update" do
24-
explain = TestRepo.explain(:update_all, from(p in Post, update: [set: [title: "new title"]]))
26+
explain =
27+
TestRepo.explain(:update_all, from(p in Post, update: [set: [title: "new title"]]))
28+
2529
assert explain =~ "UPDATE"
2630
assert explain =~ "p0"
2731
assert explain =~ "new title"
@@ -36,7 +40,7 @@ defmodule Ecto.Integration.ExplainTest do
3640
test "explain without rolling back" do
3741
{:ok, {:ok, explain}} =
3842
TestRepo.transaction(fn ->
39-
TestRepo.explain(:delete_all, Post, rollback: false, timeout: 20000)
43+
TestRepo.explain(:delete_all, Post, wrap_in_transaction: false, timeout: 20000)
4044
end)
4145

4246
assert explain =~ "DELETE"

lib/ecto/adapters/sql.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ defmodule Ecto.Adapters.SQL do
434434
435435
Adapter | Supported opts
436436
---------------- | --------------
437-
Postgrex | `analyze`, `verbose`, `costs`, `settings`, `buffers`, `timing`, `summary`, `format`, `plan`, `rollback`
438-
MyXQL | `format`, `rollback`
437+
Postgrex | `analyze`, `verbose`, `costs`, `settings`, `buffers`, `timing`, `summary`, `format`, `plan`, `wrap_in_transaction`
438+
MyXQL | `format`, `wrap_in_transaction`
439439
440440
All options except `format` are boolean valued and default to `false`.
441441
@@ -447,9 +447,9 @@ defmodule Ecto.Adapters.SQL do
447447
* Postgrex: `:map`, `:yaml` and `:text`
448448
* MyXQL: `:map` and `:text`
449449
450-
The `rollback` option is a boolean that controls whether the command is run inside of a transaction
451-
that is rolled back. This is useful when, for example, you'd like to use `analyze: true` on an update
452-
or delete query without modifying data. Defaults to `true`.
450+
The `wrap_in_transaction` option is a boolean that controls whether the command is run inside of a
451+
transaction that is rolled back. This is useful when, for example, you'd like to use `analyze: true`
452+
on an update or delete query without modifying data. Defaults to `true`.
453453
454454
The `:plan` option in Postgrex can take the values `:custom` or `:fallback_generic`. When `:custom`
455455
is specified, the explain plan generated will consider the specific values of the query parameters
@@ -512,8 +512,8 @@ defmodule Ecto.Adapters.SQL do
512512
def explain(repo, operation, queryable, opts \\ [])
513513

514514
def explain(repo, operation, queryable, opts) when is_atom(repo) or is_pid(repo) do
515-
rollback? = Keyword.get(opts, :rollback, true)
516-
explain(Ecto.Adapter.lookup_meta(repo), operation, queryable, rollback?, opts)
515+
wrap_in_transaction? = Keyword.get(opts, :wrap_in_transaction, true)
516+
explain(Ecto.Adapter.lookup_meta(repo), operation, queryable, wrap_in_transaction?, opts)
517517
end
518518

519519
def explain(%{repo: repo} = adapter_meta, operation, queryable, true, opts) do

0 commit comments

Comments
 (0)