Skip to content

Commit cc0f799

Browse files
ampagenttmm
andcommitted
docs(zero-swift): migration example in the typed mutators changeset
Amp-Thread-ID: https://ampcode.com/threads/T-01a17664-8fd0-76be-8fd5-75ac6e7aa0d8 Co-authored-by: tmm <tmm@tmm.dev>
1 parent 6b16a90 commit cc0f799

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎.changeset/typed-table-mutators.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,22 @@
22
'zero-swift': minor
33
---
44

5-
`tx.mutate.<table>` is typed, as in JS: `insert` and `upsert` take the row struct, `update` its generated `Update` (the primary key and the columns to set), and `delete` its generated `Key`. An optional column in an `Update` is a `ColumnUpdate`, so leaving it (`.unchanged`) differs from setting it to null (`.null`). Breaking: code that passed a dictionary to `tx.mutate.<table>` now uses these types, or `tx.mutate.table("<table>")` for the untyped `TableMutator`. Regenerate with `zero-swift codegen`.
5+
**Breaking:** `tx.mutate.<table>` is typed, as in JS. `insert` and `upsert` take the row struct, `update` its generated `Update` (the primary key and the columns to set), and `delete` its generated `Key`. An optional column in an `Update` is a `ColumnUpdate`, so leaving it (`.unchanged`, the default) differs from setting it to null (`.null`).
6+
7+
To migrate, regenerate with `npx zero-swift codegen`, then replace dictionaries passed to `tx.mutate.<table>` with the typed values:
8+
9+
```diff
10+
- try tx.mutate.issue.insert(["id": .string(id), "title": .string(title), ...])
11+
+ try tx.mutate.issue.insert(.init(id: id, title: title, ...))
12+
13+
- try tx.mutate.issue.update(["id": .string(id), "title": .string(title)])
14+
+ try tx.mutate.issue.update(.init(id: id, title: title))
15+
16+
- try tx.mutate.issue.update(["id": .string(id), "assigneeID": .null])
17+
+ try tx.mutate.issue.update(.init(id: id, assigneeID: .null))
18+
19+
- try tx.mutate.issue.delete(["id": .string(id)])
20+
+ try tx.mutate.issue.delete(.init(id: id))
21+
```
22+
23+
`tx.mutate.insert(row)` and `tx.mutate.upsert(row)` still work. For untyped writes, `tx.mutate.table("issue")` takes dictionaries as before.

0 commit comments

Comments
 (0)