Skip to content

Commit 00e078a

Browse files
committed
don't try our funky txid query if the db is not pg
and document the behaviour
1 parent 81c1949 commit 00e078a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/phoenix/sync/writer.ex

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ defmodule Phoenix.Sync.Writer do
8989
transaction are accepted or none are. See `apply/2` for how you can hook
9090
into the `Ecto.Multi` after applying your change data.
9191
92+
> #### Compatibility {: .info}
93+
>
94+
> `#{inspect(__MODULE__)}` can only return transaction ids when connecting to
95+
> a Postgres database (a repo with `adapter: Ecto.Adapters.Postgres`). You can
96+
> use this module for other databases, but the returned txid will be `nil`.
97+
9298
## Client Libraries
9399
94100
`#{inspect(__MODULE__)}` is not coupled to any particular client-side implementation.
@@ -434,6 +440,7 @@ defmodule Phoenix.Sync.Writer do
434440
end
435441

436442
require Record
443+
require Logger
437444

438445
Record.defrecordp(:opkey, schema: nil, operation: nil, index: 0, pk: nil)
439446

@@ -1171,8 +1178,15 @@ defmodule Phoenix.Sync.Writer do
11711178

11721179
defp txid_step(multi \\ Ecto.Multi.new()) do
11731180
Ecto.Multi.run(multi, @txid_name, fn repo, _ ->
1174-
with {:ok, %{rows: [[txid]]}} <- repo.query(@txid_query) do
1175-
{:ok, txid}
1181+
case repo.__adapter__() do
1182+
Ecto.Adapters.Postgres ->
1183+
with {:ok, %{rows: [[txid]]}} <- repo.query(@txid_query) do
1184+
{:ok, txid}
1185+
end
1186+
1187+
adapter ->
1188+
Logger.warning("Unsupported adapter #{adapter}. txid will be nil")
1189+
{:ok, nil}
11761190
end
11771191
end)
11781192
end
@@ -1469,7 +1483,7 @@ defmodule Phoenix.Sync.Writer do
14691483
end
14701484
14711485
Also supports normal fun/0 or fun/1 style transactions much like
1472-
`Ecto.Repo.transaction/2`, returning the txid of the operation:
1486+
`c:Ecto.Repo.transaction/2`, returning the txid of the operation:
14731487
14741488
{:ok, txid, todo} =
14751489
Phoenix.Sync.Writer.transaction(fn ->

0 commit comments

Comments
 (0)