Skip to content

Commit 44114eb

Browse files
authored
writer: rename the TanStackOptimistic format to TanStackDB. (#32)
As per the rename at https://github.com/TanStack/db
1 parent 70a5b18 commit 44114eb

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ See the Electric [demos](https://electric-sql.com/demos) and [documentation](htt
157157

158158
The `Phoenix.Sync.Writer` module allows you to ingest batches of writes from the client.
159159

160-
The idea is that the front-end can batch up [local optimistic writes](https://electric-sql.com/docs/guides/writes). For example using a library like [@TanStack/optimistic](https://github.com/TanStack/optimistic) or by [monitoring changes to a local embedded database](https://electric-sql.com/docs/guides/writes#through-the-db).
160+
The idea is that the front-end can batch up [local optimistic writes](https://electric-sql.com/docs/guides/writes). For example using a library like [@TanStack/db](https://github.com/TanStack/db) or by [monitoring changes to a local embedded database](https://electric-sql.com/docs/guides/writes#through-the-db).
161161

162162
These changes can be POSTed to a `Phoenix.Controller`, which then constructs a `Phoenix.Sync.Writer` instance. The writer instance authorizes and validates the writes before applying them to the database. Under the hood this uses `Ecto.Multi`, to ensure that transactions (batches of writes) are applied atomically.
163163

@@ -187,7 +187,7 @@ defmodule MutationController do
187187
# validate: Projects.Issue.changeset/2
188188
# etc.
189189
)
190-
|> Phoenix.Sync.Writer.apply(transaction, Repo, format: Format.TanstackOptimistic)
190+
|> Phoenix.Sync.Writer.apply(transaction, Repo, format: Format.TanstackDB)
191191

192192
render(conn, :mutations, txid: txid)
193193
end

lib/phoenix/sync/writer.ex

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule Phoenix.Sync.Writer do
5252
{:ok, %Transaction{operations: operations}} =
5353
#{inspect(__MODULE__)}.parse_transaction(
5454
my_encoded_txn,
55-
format: #{inspect(__MODULE__.Format.TanstackOptimistic)}
55+
format: #{inspect(__MODULE__.Format.TanstackDB)}
5656
)
5757
5858
{:ok, txid} =
@@ -89,7 +89,7 @@ defmodule Phoenix.Sync.Writer do
8989
# we don't allow deletes...
9090
{:error, "invalid delete"}
9191
end,
92-
format: #{inspect(__MODULE__.Format.TanstackOptimistic)},
92+
format: #{inspect(__MODULE__.Format.TanstackDB)},
9393
timeout: 60_000
9494
)
9595
@@ -137,7 +137,7 @@ defmodule Phoenix.Sync.Writer do
137137
## Controller example
138138
139139
For example, take a project management app that's using
140-
[@TanStack/optimistic](https://github.com/TanStack/optimistic) to batch up local
140+
[@TanStack/db](https://github.com/TanStack/db) to batch up local
141141
optimistic writes and POST them to the `Phoenix.Controller` below:
142142
143143
defmodule MutationController do
@@ -166,7 +166,7 @@ defmodule Phoenix.Sync.Writer do
166166
|> #{inspect(__MODULE__)}.apply(
167167
transaction,
168168
Repo,
169-
format: Format.TanstackOptimistic
169+
format: Format.TanstackDB
170170
)
171171
172172
render(conn, :mutations, txid: txid)
@@ -234,14 +234,13 @@ defmodule Phoenix.Sync.Writer do
234234
235235
The currently supported format adapters are:
236236
237-
- [TanStack/optimistic](https://github.com/TanStack/optimistic) "A library
238-
for creating fast optimistic updates with flexible backend support that pairs
239-
seamlessly with sync engines"
237+
- [TanStack/db](https://github.com/TanStack/db) "A reactive client store for
238+
building super fast apps on sync"
240239
241240
Integration:
242241
243242
#{inspect(__MODULE__)}.new()
244-
|> #{inspect(__MODULE__)}.ingest(mutation_data, format: #{inspect(__MODULE__.Format.TanstackOptimistic)})
243+
|> #{inspect(__MODULE__)}.ingest(mutation_data, format: #{inspect(__MODULE__.Format.TanstackDB)})
245244
|> #{inspect(__MODULE__)}.transaction(Repo)
246245
247246
## Usage
@@ -496,7 +495,7 @@ defmodule Phoenix.Sync.Writer do
496495
check: &validate_mutation(&1, user_id),
497496
load: &fetch_for_user(&1, user_id),
498497
)
499-
|> Writer.apply(transaction, Repo, format: Writer.Format.TanstackOptimistic)
498+
|> Writer.apply(transaction, Repo, format: Writer.Format.TanstackDB)
500499
501500
render(conn, :mutations, txid: txid)
502501
end
@@ -1181,7 +1180,7 @@ defmodule Phoenix.Sync.Writer do
11811180
#{inspect(__MODULE__)}.new()
11821181
|> #{inspect(__MODULE__)}.allow(MyApp.Todos.Todo, check: &my_check_function/1)
11831182
|> #{inspect(__MODULE__)}.allow(MyApp.Options.Option, check: &my_check_function/1)
1184-
|> #{inspect(__MODULE__)}.ingest(changes, format: #{inspect(__MODULE__.Format.TanstackOptimistic)})
1183+
|> #{inspect(__MODULE__)}.ingest(changes, format: #{inspect(__MODULE__.Format.TanstackDB)})
11851184
|> #{inspect(__MODULE__)}.to_multi()
11861185
11871186
If you want to add extra operations to the mutation transaction, beyond those
@@ -1284,7 +1283,7 @@ defmodule Phoenix.Sync.Writer do
12841283
#{inspect(__MODULE__)}.new()
12851284
|> #{inspect(__MODULE__)}.allow(MyApp.Todos.Todo, check: &my_check_function/1)
12861285
|> #{inspect(__MODULE__)}.allow(MyApp.Options.Option, check: &my_check_function/1)
1287-
|> #{inspect(__MODULE__)}.to_multi(changes, format: #{inspect(__MODULE__.Format.TanstackOptimistic)})
1286+
|> #{inspect(__MODULE__)}.to_multi(changes, format: #{inspect(__MODULE__.Format.TanstackDB)})
12881287
12891288
"""
12901289
@spec to_multi(t(), Format.transaction_data(), parse_opts()) :: Ecto.Multi.t()
@@ -1307,7 +1306,7 @@ defmodule Phoenix.Sync.Writer do
13071306
13081307
This can be used to handle mutation operations explicitly:
13091308
1310-
{:ok, txn} = #{inspect(__MODULE__)}.parse_transaction(my_json_tx_data, format: #{inspect(__MODULE__.Format.TanstackOptimistic)})
1309+
{:ok, txn} = #{inspect(__MODULE__)}.parse_transaction(my_json_tx_data, format: #{inspect(__MODULE__.Format.TanstackDB)})
13111310
13121311
{:ok, txid} =
13131312
Repo.transaction(fn ->
@@ -1693,7 +1692,7 @@ defmodule Phoenix.Sync.Writer do
16931692
|> #{inspect(__MODULE__)}.allow(MyApp.Options.Option)
16941693
|> #{inspect(__MODULE__)}.ingest(
16951694
changes,
1696-
format: #{inspect(__MODULE__)}.Format.TanstackOptimistic
1695+
format: #{inspect(__MODULE__)}.Format.TanstackDB
16971696
)
16981697
|> #{inspect(__MODULE__)}.transaction(MyApp.Repo)
16991698
|> case do
@@ -1772,7 +1771,7 @@ defmodule Phoenix.Sync.Writer do
17721771
# we don't allow deletes...
17731772
{:error, "invalid delete"}
17741773
end,
1775-
format: #{inspect(__MODULE__.Format.TanstackOptimistic)},
1774+
format: #{inspect(__MODULE__.Format.TanstackDB)},
17761775
timeout: 60_000
17771776
)
17781777
@@ -1784,7 +1783,7 @@ defmodule Phoenix.Sync.Writer do
17841783
{:ok, txn} =
17851784
#{inspect(__MODULE__)}.parse_transaction(
17861785
my_encoded_txn,
1787-
format: #{inspect(__MODULE__.Format.TanstackOptimistic)}
1786+
format: #{inspect(__MODULE__.Format.TanstackDB)}
17881787
)
17891788
17901789
{:ok, txid} =
@@ -1856,7 +1855,7 @@ defmodule Phoenix.Sync.Writer do
18561855
#{inspect(__MODULE__)}.new()
18571856
|> #{inspect(__MODULE__)}.allow(MyApp.Todos.Todo)
18581857
|> #{inspect(__MODULE__)}.allow(MyApp.Options.Option)
1859-
|> #{inspect(__MODULE__)}.to_multi(changes, format: #{inspect(__MODULE__)}.Format.TanstackOptimistic)
1858+
|> #{inspect(__MODULE__)}.to_multi(changes, format: #{inspect(__MODULE__)}.Format.TanstackDB)
18601859
|> MyApp.Repo.transaction()
18611860
18621861
{:ok, txid} = #{inspect(__MODULE__)}.txid(changes)

lib/phoenix/sync/writer/format/tanstack_optimistic.ex renamed to lib/phoenix/sync/writer/format/tanstack_db.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
defmodule Phoenix.Sync.Writer.Format.TanstackOptimistic do
1+
defmodule Phoenix.Sync.Writer.Format.TanstackDB do
22
@moduledoc """
33
Implements the `Phoenix.Sync.Writer.Format` behaviour for the data format used by
4-
[TanStack/optimistic](https://github.com/TanStack/optimistic).
4+
[TanStack/db](https://github.com/TanStack/db).
55
"""
66

77
alias Phoenix.Sync.Writer.Transaction

test/phoenix/sync/writer_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defmodule Phoenix.Sync.WriterTest do
111111
Writer.new()
112112
end
113113

114-
def ingest(writer, changes, opts \\ [format: Writer.Format.TanstackOptimistic]) do
114+
def ingest(writer, changes, opts \\ [format: Writer.Format.TanstackDB]) do
115115
Writer.ingest(writer, changes, opts)
116116
end
117117

@@ -860,7 +860,7 @@ defmodule Phoenix.Sync.WriterTest do
860860
Ecto.Multi.put(multi, :before_all_todo, ref)
861861
end
862862
)
863-
|> Writer.apply(changes, Repo, format: Writer.Format.TanstackOptimistic)
863+
|> Writer.apply(changes, Repo, format: Writer.Format.TanstackDB)
864864

865865
assert 1 == :atomics.get(counter, 1)
866866
end
@@ -959,7 +959,7 @@ defmodule Phoenix.Sync.WriterTest do
959959
send(parent, {op, relation, data, changes})
960960
:ok
961961
end,
962-
format: Writer.Format.TanstackOptimistic
962+
format: Writer.Format.TanstackDB
963963
)
964964

965965
assert is_integer(txid)

0 commit comments

Comments
 (0)