Repository navigation
feat(zero-swift): typed tx.mutate.<table>, as in JS - #36
Merged
Merged
Conversation
tx.mutate.issue was the untyped TableMutator (dynamic member lookup), so update and delete took dictionaries and only insert and upsert had a typed form, without the table name. Codegen now emits, per table, a TransactionMutate member returning TypedTableMutator<Row>, and nested Row.Update and Row.Key structs: - insert and upsert take the row struct; - update takes Update: the primary key, and the columns to set. A nil column keeps its value, as an undefined one does in JS. An optional column is a ColumnUpdate (.unchanged, .null, .set, or a literal), so leaving it differs from setting it to null; - delete takes Key, the primary key. Rows conform to ZeroTable (a ZeroRow with Update and Key). The untyped TableMutator stays as tx.mutate.table(name), and for tables without a generated member. Code that passed dictionaries to tx.mutate.<table> moves to the typed calls or table(name). Amp-Thread-ID: https://ampcode.com/threads/T-01a17664-8fd0-76be-8fd5-75ac6e7aa0d8 Co-authored-by: tmm <tmm@tmm.dev>
Amp-Thread-ID: https://ampcode.com/threads/T-01a17664-8fd0-76be-8fd5-75ac6e7aa0d8 Co-authored-by: tmm <tmm@tmm.dev>
Amp-Thread-ID: https://ampcode.com/threads/T-01a17664-8fd0-76be-8fd5-75ac6e7aa0d8 Co-authored-by: tmm <tmm@tmm.dev>
…ilt Update Amp-Thread-ID: https://ampcode.com/threads/T-01a17664-8fd0-76be-8fd5-75ac6e7aa0d8 Co-authored-by: tmm <tmm@tmm.dev>
Amp-Thread-ID: https://ampcode.com/threads/T-01a17664-8fd0-76be-8fd5-75ac6e7aa0d8 Co-authored-by: tmm <tmm@tmm.dev>
tx.mutate.<table> is now the one way to write, as in JS. Generic code uses TypedTableMutator<R>(tx.mutate); hand-written rows without a generated member use the untyped tx.mutate.<table> with columnValues. Amp-Thread-ID: https://ampcode.com/threads/T-01a17664-8fd0-76be-8fd5-75ac6e7aa0d8 Co-authored-by: tmm <tmm@tmm.dev>
tmm
force-pushed
the
swift-typed-mutators
branch
from
October 27, 2026 03:23
ae6eaab to
408860e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Writes in a Swift mutator now look like JS: all four
tx.mutate.<table>calls are typed.Before,
tx.mutate.issuewas the untypedTableMutator(dynamic member lookup):updateanddeletetook dictionaries, and onlyinsert/upserthad a typed form, without the table name.What changes
zero-swift codegenemits, per table, atx.mutate.<table>member returningTypedTableMutator<Row>, and nestedRow.Update(like JS'sUpdateValue) andRow.Key(DeleteID). Rows conform toZeroTable.Update, a column left nil keeps its value, as anundefinedone does in JS. An optional column is aColumnUpdate(.unchangedby default,.null,.set(x), or a literal), so leaving it differs from setting it to null.upserttakes the whole row, so it writes every column; JS keeps a column the value leaves out. Documented.tx.mutate.table("issue").issue.updateno longer round-trips its arguments through JSON.Breaking (minor): passing a dictionary to
tx.mutate.<table>no longer compiles. Regenerate, and use the typed calls ortx.mutate.table(...).Known limit: two generated schemas in one module with the same table name clash on the
tx.mutatemember, a compile error in the generated file. Nothing does this today.Verification
.unchangedwrites null.issue.updatewith an assignee set, null, and left out).table/insert/tx; columns namedUpdate/Key/row/valuewith optional enums, nullable JSON, and a compound key).tsc, oxfmt clean; DocC builds with no warnings. macOS and iOS run in CI only.