Skip to content

Commit 7c4c758

Browse files
committed
fix: return txid as binary to prevent JSON serialization issues
1 parent 85501d9 commit 7c4c758

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Changed
11+
12+
- Changed type of returned txid to binary to prevent JSON serialization issues ([#71](https://github.com/electric-sql/phoenix_sync/pull/71))
13+
814
## [0.5.0] - 2025-08-13
915

1016
### Added

lib/phoenix/sync/writer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ if Code.ensure_loaded?(Ecto) do
14131413
end
14141414

14151415
@txid_name {:__phoenix_sync__, :txid}
1416-
@txid_query "SELECT txid_current() as txid"
1416+
@txid_query "SELECT txid_current()::text as txid"
14171417

14181418
defp start_multi do
14191419
Ecto.Multi.new()

test/phoenix/sync/writer_test.exs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ defmodule Phoenix.Sync.WriterTest do
134134
end
135135
end
136136

137+
defp is_txid(txid) do
138+
is_binary(txid) && match?({_, ""}, Integer.parse(txid))
139+
end
140+
137141
# new creates without applying (so doesn't need a repo)
138142
# apply creates and applies i.e. new() |> Repo.transaction()
139143
describe "allow/2" do
@@ -291,7 +295,7 @@ defmodule Phoenix.Sync.WriterTest do
291295
assert %Ecto.Multi{} = multi = Writer.to_multi(writer)
292296
assert {:ok, txid, _values} = Writer.transaction(multi, Repo)
293297

294-
assert is_integer(txid)
298+
assert is_txid(txid)
295299

296300
# validate that the callbacks are being called
297301

@@ -892,7 +896,7 @@ defmodule Phoenix.Sync.WriterTest do
892896

893897
assert {:ok, txid} = Writer.txid(changes)
894898

895-
assert is_integer(txid)
899+
assert is_txid(txid)
896900

897901
assert txid == Writer.txid!(changes)
898902
end
@@ -962,7 +966,7 @@ defmodule Phoenix.Sync.WriterTest do
962966
format: Writer.Format.TanstackDB
963967
)
964968

965-
assert is_integer(txid)
969+
assert is_txid(txid)
966970
assert_receive {:insert, ["public", "todos_local"], %{}, %{"id" => "98"}}
967971
assert_receive {:insert, ["public", "todos_local"], %{}, %{"id" => "99"}}
968972
assert_receive {:delete, ["public", "todos_local"], %{"id" => "2"}, %{}}
@@ -1003,7 +1007,7 @@ defmodule Phoenix.Sync.WriterTest do
10031007
%Support.Todo{id: 100, title: _, completed: false}
10041008
] = Repo.all(from(t in Support.Todo, order_by: t.id))
10051009

1006-
assert is_integer(txid)
1010+
assert is_txid(txid)
10071011
end
10081012

10091013
test ":error tuples rollback the transaction" do

0 commit comments

Comments
 (0)