Mutations

A mutation is a query and a patch together. The query selects the entities, and the patch gives the new state of each one. Stardust commits every change in one transaction. Each example reads the same five entities as Queries.

The document

A mutation document has query and patch. The query is an ordinary query, and the patch follows the form in Patches.

TRON222 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
042C 3F65txt "?e"
070E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
142C 3F65txt "?e"
174C 64657074txt "dept"
1C3C 6F7073txt "ops"
200E 15 00 0700 030000 00 14000000 170000 00 1C000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @14 → @17 → @1C
350E 0D 00 0100 010000 00 20000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @20
425C 7768657265txt "where"
480F 0A 42000000 3500 0000map leaf, size 10: @42 → @35
524C 66696E64txt "find"
570F 0A 52000000 0700 0000map leaf, size 10: @52 → @7
6107 0E 0A000000 4800 0000 57000000map branch, size 14, depth 0 (root), slots 1, 3: @48 → @57
6F6C 737461747573txt "status"
766C 616374697665txt "active"
7D0F 0A 6F000000 7600 0000map leaf, size 10: @6F → @76
872C 3F65txt "?e"
8A0F 0A 87000000 7D00 0000map leaf, size 10: @87 → @7D
945C 7175657279txt "query"
9A0F 0A 94000000 6100 0000map leaf, size 10: @94 → @61
A45C 7061746368txt "patch"
AA0F 0A A4000000 8A00 0000map leaf, size 10: @A4 → @8A
B407 0E 40020000 9A00 0000 AA000000map branch, size 14, depth 2, slots 6, 9: @9A → @AA
C207 0A 01000000 B400 0000map branch, size 10, depth 1, slots 0: @B4
CC07 0A 80000000 C200 0000map branch, size 10, depth 0 (root), slots 7: @C2

Each key of the patch is a target. A key that begins with ? uses an entity variable bound by the query. A key that begins with _ makes a new entity.

Preview and commit

The native mutation run commits the selection and resolved patch together. The core also has a preview path that validates the same selection, resolution and store rules without writing facts. The public ABI does not currently expose that preview.

The result blocks on this page show the core report's status and counts. The public mutation result uses lowercase status names and also gives the commit time and generated entity ids.

TRON146 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 737461747573txt "status"
0B9C 436F6D6D697474 6564txt "Committed"
150F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
1FBC 7472616E736163 74696F6Etxt "transaction"
2B02 07000000000000 00i64 7
340F 0A 1F000000 2B00 0000map leaf, size 10: @1F → @2B
3E9C 67656E65726174 6564txt "generated"
4802 00000000000000 00i64 0
510F 0A 3E000000 4800 0000map leaf, size 10: @3E → @48
5B5C 6661637473txt "facts"
6102 01000000000000 00i64 1
6A0F 0A 5B000000 6100 0000map leaf, size 10: @5B → @61
7407 16 01620000 1500 0000 34000000 5100 0000 6A000000map branch, size 22, depth 0 (root), slots 0, 9, 13, 14: @15 → @34 → @51 → @6A

The three statuses

StatusMeaning
CommittedThe patch writes facts in a new transaction
No_ChangeThe selection matches and every field already agrees
No_MatchThe selection matches no entity

A second run of the same mutation changes nothing, so Stardust commits no new transaction.

TRON146 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 737461747573txt "status"
0B9C 4E6F5F4368616E 6765txt "No_Change"
150F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
1FBC 7472616E736163 74696F6Etxt "transaction"
2B02 00000000000000 00i64 0
340F 0A 1F000000 2B00 0000map leaf, size 10: @1F → @2B
3E9C 67656E65726174 6564txt "generated"
4802 00000000000000 00i64 0
510F 0A 3E000000 4800 0000map leaf, size 10: @3E → @48
5B5C 6661637473txt "facts"
6102 00000000000000 00i64 0
6A0F 0A 5B000000 6100 0000map leaf, size 10: @5B → @61
7407 16 01620000 1500 0000 34000000 5100 0000 6A000000map branch, size 22, depth 0 (root), slots 0, 9, 13, 14: @15 → @34 → @51 → @6A

A selection that matches no entity gives the same counts. No entity is in the department legal:

TRON224 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
042C 3F65txt "?e"
070E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
142C 3F65txt "?e"
174C 64657074txt "dept"
1C5C 6C6567616Ctxt "legal"
220E 15 00 0700 030000 00 14000000 170000 00 1C000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @14 → @17 → @1C
370E 0D 00 0100 010000 00 22000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @22
445C 7768657265txt "where"
4A0F 0A 44000000 3700 0000map leaf, size 10: @44 → @37
544C 66696E64txt "find"
590F 0A 54000000 0700 0000map leaf, size 10: @54 → @7
6307 0E 0A000000 4A00 0000 59000000map branch, size 14, depth 0 (root), slots 1, 3: @4A → @59
716C 737461747573txt "status"
786C 616374697665txt "active"
7F0F 0A 71000000 7800 0000map leaf, size 10: @71 → @78
892C 3F65txt "?e"
8C0F 0A 89000000 7F00 0000map leaf, size 10: @89 → @7F
965C 7175657279txt "query"
9C0F 0A 96000000 6300 0000map leaf, size 10: @96 → @63
A65C 7061746368txt "patch"
AC0F 0A A6000000 8C00 0000map leaf, size 10: @A6 → @8C
B607 0E 40020000 9C00 0000 AC000000map branch, size 14, depth 2, slots 6, 9: @9C → @AC
C407 0A 01000000 B600 0000map branch, size 10, depth 1, slots 0: @B6
CE07 0A 80000000 C400 0000map branch, size 10, depth 0 (root), slots 7: @C4
TRON145 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 737461747573txt "status"
0B8C 4E6F5F4D617463 68txt "No_Match"
140F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
1EBC 7472616E736163 74696F6Etxt "transaction"
2A02 00000000000000 00i64 0
330F 0A 1E000000 2A00 0000map leaf, size 10: @1E → @2A
3D9C 67656E65726174 6564txt "generated"
4702 00000000000000 00i64 0
500F 0A 3D000000 4700 0000map leaf, size 10: @3D → @47
5A5C 6661637473txt "facts"
6002 00000000000000 00i64 0
690F 0A 5A000000 6000 0000map leaf, size 10: @5A → @60
7307 16 01620000 1400 0000 33000000 5000 0000 69000000map branch, size 22, depth 0 (root), slots 0, 9, 13, 14: @14 → @33 → @50 → @69

New entities

A target that begins with _ makes an entity. The selection must give exactly one row, because one new entity needs one parent row.

TRON251 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
042C 3F65txt "?e"
070E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
142C 3F65txt "?e"
174C 64657074txt "dept"
1C3C 6F7073txt "ops"
200E 15 00 0700 030000 00 14000000 170000 00 1C000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @14 → @17 → @1C
350E 0D 00 0100 010000 00 20000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @20
425C 7768657265txt "where"
480F 0A 42000000 3500 0000map leaf, size 10: @42 → @35
524C 66696E64txt "find"
570F 0A 52000000 0700 0000map leaf, size 10: @52 → @7
615C 6C696D6974txt "limit"
6702 01000000000000 00i64 1
700F 0A 61000000 6700 0000map leaf, size 10: @61 → @67
7A07 12 2A000000 4800 0000 57000000 7000 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @48 → @57 → @70
8C6C 737461747573txt "status"
934C 73656564txt "seed"
980F 0A 8C000000 9300 0000map leaf, size 10: @8C → @93
A24C 5F6E6577txt "_new"
A70F 0A A2000000 9800 0000map leaf, size 10: @A2 → @98
B15C 7175657279txt "query"
B70F 0A B1000000 7A00 0000map leaf, size 10: @B1 → @7A
C15C 7061746368txt "patch"
C70F 0A C1000000 A700 0000map leaf, size 10: @C1 → @A7
D107 0E 40020000 B700 0000 C7000000map branch, size 14, depth 2, slots 6, 9: @B7 → @C7
DF07 0A 01000000 D100 0000map branch, size 10, depth 1, slots 0: @D1
E907 0A 80000000 DF00 0000map branch, size 10, depth 0 (root), slots 7: @DF
TRON146 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 737461747573txt "status"
0B9C 436F6D6D697474 6564txt "Committed"
150F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
1FBC 7472616E736163 74696F6Etxt "transaction"
2B02 09000000000000 00i64 9
340F 0A 1F000000 2B00 0000map leaf, size 10: @1F → @2B
3E9C 67656E65726174 6564txt "generated"
4802 01000000000000 00i64 1
510F 0A 3E000000 4800 0000map leaf, size 10: @3E → @48
5B5C 6661637473txt "facts"
6102 01000000000000 00i64 1
6A0F 0A 5B000000 6100 0000map leaf, size 10: @5B → @61
7407 16 01620000 1500 0000 34000000 5100 0000 6A000000map branch, size 22, depth 0 (root), slots 0, 9, 13, 14: @15 → @34 → @51 → @6A

The engine rejects the same patch against a selection of two rows. Two entities are in the department eng:

TRON222 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
042C 3F65txt "?e"
070E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
142C 3F65txt "?e"
174C 64657074txt "dept"
1C3C 656E67txt "eng"
200E 15 00 0700 030000 00 14000000 170000 00 1C000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @14 → @17 → @1C
350E 0D 00 0100 010000 00 20000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @20
425C 7768657265txt "where"
480F 0A 42000000 3500 0000map leaf, size 10: @42 → @35
524C 66696E64txt "find"
570F 0A 52000000 0700 0000map leaf, size 10: @52 → @7
6107 0E 0A000000 4800 0000 57000000map branch, size 14, depth 0 (root), slots 1, 3: @48 → @57
6F6C 737461747573txt "status"
764C 73656564txt "seed"
7B0F 0A 6F000000 7600 0000map leaf, size 10: @6F → @76
854C 5F6E6577txt "_new"
8A0F 0A 85000000 7B00 0000map leaf, size 10: @85 → @7B
945C 7175657279txt "query"
9A0F 0A 94000000 6100 0000map leaf, size 10: @94 → @61
A45C 7061746368txt "patch"
AA0F 0A A4000000 8A00 0000map leaf, size 10: @A4 → @8A
B407 0E 40020000 9A00 0000 AA000000map branch, size 14, depth 2, slots 6, 9: @9A → @AA
C207 0A 01000000 B400 0000map branch, size 10, depth 1, slots 0: @B4
CC07 0A 80000000 C200 0000map branch, size 10, depth 0 (root), slots 7: @C2

Error

Generate_Requires_Single

Patch values and variables

The body for each target is a merge patch. It accepts every Stardust value: numbers, text, booleans, lists, maps, links and the other typed values. A null removes the field.

TRON64 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
043C 616765txt "age"
0802 05000000000000 00i64 5
110F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
1B2C 3F65txt "?e"
1E0F 0A 1B000000 1100 0000map leaf, size 10: @1B → @11
285C 7061746368txt "patch"
2E0F 0A 28000000 1E00 0000map leaf, size 10: @28 → @1E

This sets age to 5 on every entity bound to ?e.

The query may bind a patch variable in where or expose it through find. Both forms refer to the same row binding. A variable used as a patch target must bind an entity. A variable used as a field value substitutes its complete bound value.

TRON354 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0047C 3F737461747573txt "?status"
00C0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
0192C 3F65txt "?e"
01C6C 737461747573txt "status"
0237C 3F737461747573txt "?status"
02B0E 15 00 0700 030000 00 19000000 1C0000 00 23000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @19 → @1C → @23
0401C 3Dtxt "="
0427C 3F737461747573txt "?status"
04A7C 70656E64696E67txt "pending"
0520E 15 00 0700 030000 00 40000000 420000 00 4A000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @40 → @42 → @4A
0676C 3F6F776E6572txt "?owner"
06E4C 6E616D65txt "name"
0733C 416461txt "Ada"
0770E 15 00 0700 030000 00 67000000 6E0000 00 73000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @67 → @6E → @73
08C0E 15 00 0700 030000 00 2B000000 520000 00 77000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @2B → @52 → @77
0A15C 7768657265txt "where"
0A70F 0A A1000000 8C00 0000map leaf, size 10: @A1 → @8C
0B14C 66696E64txt "find"
0B60F 0A B1000000 0C00 0000map leaf, size 10: @B1 → @C
0C007 0E 0A000000 A700 0000 B6000000map branch, size 14, depth 0 (root), slots 1, 3: @A7 → @B6
0CE6C 737461747573txt "status"
0D56C 616374697665txt "active"
0DC0F 0A CE000000 D500 0000map leaf, size 10: @CE → @D5
0E65C 6F776E6572txt "owner"
0EC6C 3F6F776E6572txt "?owner"
0F30F 0A E6000000 EC00 0000map leaf, size 10: @E6 → @EC
0FD07 0E 03000000 DC00 0000 F3000000map branch, size 14, depth 0 (root), slots 0, 1: @DC → @F3
10B2C 3F65txt "?e"
10E0F 0A 0B010000 FD00 0000map leaf, size 10: @10B → @FD
1185C 7175657279txt "query"
11E0F 0A 18010000 C000 0000map leaf, size 10: @118 → @C0
1285C 7061746368txt "patch"
12E0F 0A 28010000 0E01 0000map leaf, size 10: @128 → @10E
13807 0E 40020000 1E01 0000 2E010000map branch, size 14, depth 2, slots 6, 9: @11E → @12E
14607 0A 01000000 3801 0000map branch, size 10, depth 1, slots 0: @138
15007 0A 80000000 4601 0000map branch, size 10, depth 0 (root), slots 7: @146

Stardust rejects a mutation with a malformed patch or an unbound variable. It also rejects a target that does not bind an entity or writes a protected stardust/* field. An invalid typed value or a result that violates the selected schema also causes rejection.

A mutation cannot write a definition. Stardust rejects a definition target with Definition_Target. Definitions include schemas, queries and mutations. A patch that writes stardust/type also gives Definition_Target. The preview gives the same error, and no fact changes. Use the definition API to change a definition.

Run it

mutation run.