Queries and mutations

The example stores the people in a database and queries their names. It collects query pages, updates Ada's age, and reads the changed age.

The optional adaptive query planner learns from runs and compares alternative plans for stored queries. Enable it through the database's plugins open option.

Example

The example compares these results:

  • a committed mutation
  • a repeated mutation
  • a query that matches no entity

Give Ada her birthday and read her age

birthday-text holds this document:

TRON221 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 6E616D65txt "name"
1C3C 416461txt "Ada"
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
6F3C 616765txt "age"
7302 25000000000000 00i64 37
7C0F 0A 6F000000 7300 0000map leaf, size 10: @6F → @73
862C 3F65txt "?e"
890F 0A 86000000 7C00 0000map leaf, size 10: @86 → @7C
935C 7175657279txt "query"
990F 0A 93000000 6100 0000map leaf, size 10: @93 → @61
A35C 7061746368txt "patch"
A90F 0A A3000000 8900 0000map leaf, size 10: @A3 → @89
B307 0E 40020000 9900 0000 A9000000map branch, size 14, depth 2, slots 6, 9: @99 → @A9
C107 0A 01000000 B300 0000map branch, size 10, depth 1, slots 0: @B3
CB07 0A 80000000 C100 0000map branch, size 10, depth 0 (root), slots 7: @C1

query-text holds this document:

TRON158 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 3F616765txt "?age"
090E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
162C 3F65txt "?e"
194C 6E616D65txt "name"
1E3C 416461txt "Ada"
220E 15 00 0700 030000 00 16000000 190000 00 1E000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @16 → @19 → @1E
372C 3F65txt "?e"
3A3C 616765txt "age"
3E4C 3F616765txt "?age"
430E 15 00 0700 030000 00 37000000 3A0000 00 3E000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @37 → @3A → @3E
580E 11 00 0300 020000 00 22000000 430000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @22 → @43
695C 7768657265txt "where"
6F0F 0A 69000000 5800 0000map leaf, size 10: @69 → @58
794C 66696E64txt "find"
7E0F 0A 79000000 0900 0000map leaf, size 10: @79 → @9
8807 0E 0A000000 6F00 0000 7E000000map branch, size 14, depth 0 (root), slots 1, 3: @6F → @7E
clojure266 B
(with-open [source (sd/parse birthday-text :tron)
            birthday (sd/mutation db source)]
  (sd/run birthday))
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            rows (sd/run query)]
  (sd/all-pages rows))
TRON48 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
043C 616765txt "age"
0802 25000000000000 00i64 37
110F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
1B0E 0D 00 0100 010000 00 11000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @11

Query pages

Each query page is an owned document.

  • You can keep a page after you release the rows handle, query, or database that produced it.
  • Release each page when you finish with its values. The document ownership rule applies.

Cached joins

The database can keep completed native fact joins as owned binding rows before aggregation. When you run the same query and plan again, the cache can supply those rows at the same database snapshot. Aggregates and output expressions still run for each call.

The cache uses the database working-memory budget and gives memory back when queries need it. The cache discards rows from joins that do not complete. After a write, new queries use a new snapshot. An active reader keeps the rows from its original snapshot.

Parameterized, temporal and overlay queries use their normal execution paths. Queries with predicates, derivations, member clauses or transaction terms also use those paths. Background planner trials and sampled foreground measurements execute joins directly.

Exact indexes

A query or mutation definition that compares a field with a value makes the database build that field's exact index. The comparison is a fact clause with a constant or a parameter value, or a =, <, <=, >, >= or hasPrefix predicate on a fact clause's value. With the index, a hasPrefix predicate reads only the texts that start with the prefix, and no value of another type.

  • Storing the definition starts the build. An inline query or mutation that compares a field the same way also starts one.
  • The database builds the index in the background, including the values committed before the definition. The call that started it does not wait.
  • Queries scan the field until its index is ready. The results are the same; only the time differs.
  • Use indexes_sync to wait until every index that earlier definitions and inline runs ask for is ready, for example before you measure a query.
  • An index that no definition uses any more stays until the database next opens.

Operations

OperationReturnsSummary
read-entitydocumentdatabase.read_entity(entity, max_depth, max_entities) atomically returns an owned {document links revisions truncated} document, expanding links up to max_depth hops.
queryqueryOpen an owned query from a path or an inline definition.
mutationmutationOpen an owned mutation from a path or an inline definition.
runrowsRun the query and return an owned row cursor.
closenoneRelease the query handle.
nextdocumentRead the next page as an owned document.
pagespagesrows.pages() iterates the non-empty pages of the cursor.
all-pagesdocumentrows.all_pages() reads every remaining page into one owned array document.
closenoneRelease the rows handle.
subscribesubscriptionquery.subscribe(parameters, options) opens an owned live subscription.
nexteventWait for the next live event.
eventsUnavailablesubscription.events() delivers events in order until the subscription is cancelled, closes or fails.
cancelnonesubscription.cancel() ends the subscription.
closenoneRelease the subscription handle.
runcommitRun the mutation and return commit information.
closenoneRelease the mutation handle.
merge-patchcommitdatabase.merge_patch(patch) applies an entity-keyed patch document in one transaction and returns commit information.
indexes-syncnonedatabase.indexes_sync(max_wait) waits until the database built every exact index that earlier definition commits and inline runs ask for.
bulk-beginnonedatabase.bulk_begin() starts a bulk build of data merge patches held by the database.
bulk-addnonedatabase.bulk_add(patch) copies and queues one merge-patch document in the bulk build.
bulk-finishdocumentdatabase.bulk_finish() publishes the bulk build with one commit, ends it and returns an owned summary document.
bulk-abortnonedatabase.bulk_abort() drops the bulk build in progress without writing it.

read-entity

clojure11 B
[db entity]
clojure34 B
[db entity max-depth max-entities]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
entityIntegerValueRequiredThe decimal user entity ID.
max-depthIntegerValueAbsentLink hops to expand along each path, 0 through 32. 0, the default, leaves every link a {#link id} reference.
max-entitiesIntegerValueAbsentThe most entity documents the result holds, counting the root and every expanded or absent target each time it is placed. 0 selects the default of 1000.

Errors

StatusWhen
:invalid-argumentthe entity ID is outside the user entity range, max_depth is negative or above 32, or max_entities is negative
:closedthe database is closed
:out-of-memorynative memory is exhausted

Notes

revisions maps each placed entity's decimal ID to its last-touch transaction for #_tx.stardust/checkAndSet. Empty object and array fields are omitted recursively. See entity reads for result fields, JSON Pointer links and expansion rules.

Examples

Read Bob with his mentor expanded

clojure25 B
(sd/read-entity db 2 1 0)
TRON408 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0043C 616765txt "age"
00802 24000000000000 00i64 36
0110F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
01B4C 726F6C65txt "role"
0208C 656E67696E6565 72txt "engineer"
0290F 0A 1B000000 2000 0000map leaf, size 10: @1B → @20
0334C 6E616D65txt "name"
0383C 416461txt "Ada"
03C0F 0A 33000000 3800 0000map leaf, size 10: @33 → @38
04607 12 00910000 1100 0000 29000000 3C00 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @11 → @29 → @3C
0583C 616765txt "age"
05C02 29000000000000 00i64 41
0650F 0A 58000000 5C00 0000map leaf, size 10: @58 → @5C
06F6C 6D656E746F72txt "mentor"
0760F 0A 6F000000 4600 0000map leaf, size 10: @6F → @46
0804C 726F6C65txt "role"
0858C 656E67696E6565 72txt "engineer"
08E0F 0A 80000000 8500 0000map leaf, size 10: @80 → @85
0984C 6E616D65txt "name"
09D3C 426F62txt "Bob"
0A10F 0A 98000000 9D00 0000map leaf, size 10: @98 → @9D
0AB07 16 00990000 6500 0000 76000000 8E00 0000 A1000000map branch, size 22, depth 0 (root), slots 8, 11, 12, 15: @65 → @76 → @8E → @A1
0C15C 236C696E6Btxt "#link"
0C702 01000000000000 00i64 1
0D00F 0A C1000000 C700 0000map leaf, size 10: @C1 → @C7
0DA7C 2F6D656E746F72txt "/mentor"
0E20F 0A DA000000 D000 0000map leaf, size 10: @DA → @D0
0EC1C 31txt "1"
0EE02 04000000000000 00i64 4
0F70F 0A EC000000 EE00 0000map leaf, size 10: @EC → @EE
1011C 32txt "2"
10302 04000000000000 00i64 4
10C0F 0A 01010000 0301 0000map leaf, size 10: @101 → @103
11607 0E 14000000 F700 0000 0C010000map branch, size 14, depth 0 (root), slots 2, 4: @F7 → @10C
1249C 7472756E636174 6564txt "truncated"
12E01bit false
12F0F 0A 24010000 2E01 0000map leaf, size 10: @124 → @12E
1398C 646F63756D656E 74txt "document"
1420F 0A 39010000 AB00 0000map leaf, size 10: @139 → @AB
14C5C 6C696E6B73txt "links"
1520F 0A 4C010000 E200 0000map leaf, size 10: @14C → @E2
15C07 0E 20100000 4201 0000 52010000map branch, size 14, depth 1, slots 5, 12: @142 → @152
16A9C 7265766973696F 6E73txt "revisions"
1740F 0A 6A010000 1601 0000map leaf, size 10: @16A → @116
17E07 12 82200000 2F01 0000 5C010000 7401 0000map branch, size 18, depth 0 (root), slots 1, 7, 13: @12F → @15C → @174

C exports: stardust_db_read_entity, stardust_result_take_document, stardust_result_error, stardust_result_release

query

clojure11 B
[db source]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
sourceSourceValueRequiredAn inline native definition or a stored definition path.

Errors

StatusWhen
:not-foundno definition is stored at the path
:invalid-definitionthe definition is invalid
:closedthe database is closed
:out-of-memorynative memory is exhausted

Notes

Inline definitions are copied. Stored paths select their definition at run time.

Query documents.

Examples

Open an inline query and read its first page

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure144 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            rows (sd/run query)]
  (sd/next rows))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

Refuse an invalid query definition

definition-text holds this document:

TRON43 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
042C 3F78txt "?x"
070E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
144C 66696E64txt "find"
190F 0A 14000000 0700 0000map leaf, size 10: @14 → @7
clojure84 B
(with-open [definition (sd/parse definition-text :tron)]
  (sd/query db definition))
TRON231 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 737461747573txt "status"
0B14 12 696E76616C69 645F646566696E69 74696F6Etxt "invalid_definition"
1F0F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
296C 656E74697479txt "entity"
3000nil
310F 0A 29000000 3000 0000map leaf, size 10: @29 → @30
3B7C 6D657373616765txt "message"
4314 10 556E626F756E 645F566172696162 6C65txt "Unbound_Variable"
550F 0A 3B000000 4300 0000map leaf, size 10: @3B → @43
5F07 0E 08020000 3100 0000 55000000map branch, size 14, depth 1, slots 3, 9: @31 → @55
6D4C 70617468txt "path"
7200nil
730F 0A 6D000000 7200 0000map leaf, size 10: @6D → @72
7D5C 6669656C64txt "field"
8300nil
840F 0A 7D000000 8300 0000map leaf, size 10: @7D → @83
8E4C 636F6465txt "code"
9314 10 756E626F756E 645F766172696162 6C65txt "unbound_variable"
A50F 0A 8E000000 9300 0000map leaf, size 10: @8E → @93
AF6C 6F6666736574txt "offset"
B600nil
B70F 0A AF000000 B600 0000map leaf, size 10: @AF → @B6
C107 1E 51620000 1F00 0000 5F000000 7300 0000 84000000 A500 0000 B7000000map branch, size 30, depth 0 (root), slots 0, 4, 6, 9, 13, 14: @1F → @5F → @73 → @84 → @A5 → @B7

Report a missing stored query

clojure30 B
(sd/query db "people/missing")
TRON237 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 737461747573txt "status"
0B9C 6E6F745F666F75 6E64txt "not_found"
150F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
1F6C 656E74697479txt "entity"
2600nil
270F 0A 1F000000 2600 0000map leaf, size 10: @1F → @26
317C 6D657373616765txt "message"
3914 1A 6E6F20646566 696E6974696F6E20 6174207468697320 70617468txt "no definition at this pa…"
550F 0A 31000000 3900 0000map leaf, size 10: @31 → @39
5F07 0E 08020000 2700 0000 55000000map branch, size 14, depth 1, slots 3, 9: @27 → @55
6D4C 70617468txt "path"
72EC 70656F706C652F 6D697373696E67txt "people/missing"
810F 0A 6D000000 7200 0000map leaf, size 10: @6D → @72
8B5C 6669656C64txt "field"
9100nil
920F 0A 8B000000 9100 0000map leaf, size 10: @8B → @91
9C4C 636F6465txt "code"
A19C 6E6F745F666F75 6E64txt "not_found"
AB0F 0A 9C000000 A100 0000map leaf, size 10: @9C → @A1
B56C 6F6666736574txt "offset"
BC00nil
BD0F 0A B5000000 BC00 0000map leaf, size 10: @B5 → @BC
C707 1E 51620000 1500 0000 5F000000 8100 0000 92000000 AB00 0000 BD000000map branch, size 30, depth 0 (root), slots 0, 4, 6, 9, 13, 14: @15 → @5F → @81 → @92 → @AB → @BD

C exports: stardust_db_query_open, stardust_db_query_error

mutation

clojure11 B
[db source]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
sourceSourceValueRequiredAn inline native definition or a stored definition path.

Errors

StatusWhen
:not-foundno definition is stored at the path
:invalid-definitionthe definition is invalid
:closedthe database is closed
:out-of-memorynative memory is exhausted

Notes

Inline definitions are copied. Stored paths select their definition at run time.

Mutation documents.

Examples

database/mutation

birthday-text holds this document:

TRON221 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 6E616D65txt "name"
1C3C 416461txt "Ada"
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
6F3C 616765txt "age"
7302 25000000000000 00i64 37
7C0F 0A 6F000000 7300 0000map leaf, size 10: @6F → @73
862C 3F65txt "?e"
890F 0A 86000000 7C00 0000map leaf, size 10: @86 → @7C
935C 7175657279txt "query"
990F 0A 93000000 6100 0000map leaf, size 10: @93 → @61
A35C 7061746368txt "patch"
A90F 0A A3000000 8900 0000map leaf, size 10: @A3 → @89
B307 0E 40020000 9900 0000 A9000000map branch, size 14, depth 2, slots 6, 9: @99 → @A9
C107 0A 01000000 B300 0000map branch, size 10, depth 1, slots 0: @B3
CB07 0A 80000000 C100 0000map branch, size 10, depth 0 (root), slots 7: @C1
clojure116 B
(with-open [source (sd/parse birthday-text :tron)
            mutation (sd/mutation db source)]
  (sd/run mutation))
TRON179 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
040F 02map leaf, size 2
063C 696473txt "ids"
0A0F 0A 06000000 0400 0000map leaf, size 10: @6 → @4
146C 737461747573txt "status"
1B9C 636F6D6D697474 6564txt "committed"
250F 0A 14000000 1B00 0000map leaf, size 10: @14 → @1B
2F07 0E 02040000 0A00 0000 25000000map branch, size 14, depth 1, slots 1, 10: @A → @25
3DBC 7472616E736163 74696F6Etxt "transaction"
4902 05000000000000 00i64 5
520F 0A 3D000000 4900 0000map leaf, size 10: @3D → @49
5CCC 636F6D6D697474 65645F6174txt "committed_at"
6902 8CAAE83F35AD3F 00i64 17923367749855884
720F 0A 5C000000 6900 0000map leaf, size 10: @5C → @69
7C5C 6661637473txt "facts"
8202 01000000000000 00i64 1
8B0F 0A 7C000000 8200 0000map leaf, size 10: @7C → @82
9507 16 01460000 2F00 0000 52000000 7200 0000 8B000000map branch, size 22, depth 0 (root), slots 0, 9, 10, 14: @2F → @52 → @72 → @8B

C exports: stardust_db_mutation_open, stardust_db_mutation_error

run

clojure8 B
[handle]
clojure19 B
[handle parameters]
clojure50 B
[handle parameters {:keys [max-cost] :as options}]

Parameters

ParameterTypeOwnershipDefaultMeaning
handleQueryBorrowed for the callRequiredThe query owner for this operation. Keep it alive during the call.
parametersDocumentBorrowed for the callAbsent means no supplied parametersAn optional object of parameter values that merge-patches the definition's declared parameters. A parameter matched in the entity position of a fact clause takes an entity reference {#link id}, never the bare ID number: a commit returns IDs as numbers, so wrap one as {#link id}, or as the typed Link value where the binding has one, before passing it. A query run fails with entity_reference_expected when a bare number reaches that position. Projected and found entities also read back as {#link id}, so a typed field that receives one uses Link rather than a plain integer.
optionsrun-optionsValueAbsent selects operation defaultsThe operation's options record. See its field defaults.

Errors

StatusWhen
:not-foundthe stored query definition was deleted
:invalid-definitionthe loaded query definition is invalid
:invalid-argumentthe parameters or run options are invalid
:evaluation-failedthe query fails or exceeds max_cost
:closedthe query is closed
:out-of-memorynative memory is exhausted

Notes

Query documents.

Examples

Open an inline query and read its first page

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure144 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            rows (sd/run query)]
  (sd/next rows))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

Capture the host duration boundary

boundary-text holds this document:

TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 FFFFFFFFFFFFFF 7Fi64 9223372036854775807

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure357 B
(with-open [boundary (sd/parse boundary-text :tron)
            definition (sd/parse query-text :tron)
            query (sd/query db definition)]
  (let [max-cost (java.time.Duration/ofSeconds (sd/i64 boundary (sd/root boundary)))
        options {:page-size 2 :max-cost max-cost :as-of 0}]
    (with-open [rows (sd/run query nil options)]
      options)))
TRON112 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
048C 6D61785F636F73 74txt "max_cost"
0D02 FFFFFFFFFFFFFF 7Fi64 9223372036854775807
160F 0A 04000000 0D00 0000map leaf, size 10: @4 → @D
205C 61735F6F66txt "as_of"
2602 00000000000000 00i64 0
2F0F 0A 20000000 2600 0000map leaf, size 10: @20 → @26
399C 706167655F7369 7A65txt "page_size"
4302 02000000000000 00i64 2
4C0F 0A 39000000 4300 0000map leaf, size 10: @39 → @43
5607 12 28200000 1600 0000 2F000000 4C00 0000map branch, size 18, depth 0 (root), slots 3, 5, 13: @16 → @2F → @4C

Truncate a positive sub-tick duration

boundary-text holds this document:

TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 63000000000000 00i64 99

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure355 B
(with-open [boundary (sd/parse boundary-text :tron)
            definition (sd/parse query-text :tron)
            query (sd/query db definition)]
  (let [max-cost (java.time.Duration/ofNanos (sd/i64 boundary (sd/root boundary)))
        options {:page-size 2 :max-cost max-cost :as-of 0}]
    (with-open [rows (sd/run query nil options)]
      options)))
TRON112 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
048C 6D61785F636F73 74txt "max_cost"
0D02 00000000000000 00i64 0
160F 0A 04000000 0D00 0000map leaf, size 10: @4 → @D
205C 61735F6F66txt "as_of"
2602 00000000000000 00i64 0
2F0F 0A 20000000 2600 0000map leaf, size 10: @20 → @26
399C 706167655F7369 7A65txt "page_size"
4302 02000000000000 00i64 2
4C0F 0A 39000000 4300 0000map leaf, size 10: @39 → @43
5607 12 28200000 1600 0000 2F000000 4C00 0000map branch, size 18, depth 0 (root), slots 3, 5, 13: @16 → @2F → @4C

Explain query execution

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure187 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            ^java.io.Closeable rows (sd/run query nil {:explain? true})]
  (sd/explain rows))
TRON1.1 kB
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
004BC 6172656E615F62 79746573txt "arena_bytes"
01002 90060000000000 00i64 1680
0190F 0A 04000000 1000 0000map leaf, size 10: @4 → @10
0233C 637075txt "cpu"
02702 AE010000000000 00i64 430
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 B4010000000000 00i64 436
0480F 0A 3A000000 3F00 0000map leaf, size 10: @3A → @3F
05207 12 21800000 1900 0000 30000000 4800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @19 → @30 → @48
064BC 6172656E615F62 79746573txt "arena_bytes"
07002 00000000000000 00i64 0
0790F 0A 64000000 7000 0000map leaf, size 10: @64 → @70
0833C 637075txt "cpu"
08702 04000000000000 00i64 4
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 06000000000000 00i64 6
0A80F 0A 9A000000 9F00 0000map leaf, size 10: @9A → @9F
0B207 12 21800000 7900 0000 90000000 A800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @79 → @90 → @A8
0C4BC 6172656E615F62 79746573txt "arena_bytes"
0D002 001D0000000000 00i64 7424
0D90F 0A C4000000 D000 0000map leaf, size 10: @C4 → @D0
0E33C 637075txt "cpu"
0E702 341B0000000000 00i64 6964
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 331B0000000000 00i64 6963
1080F 0A FA000000 FF00 0000map leaf, size 10: @FA → @FF
11207 12 21800000 D900 0000 F0000000 0801 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @D9 → @F0 → @108
124BC 6172656E615F62 79746573txt "arena_bytes"
Show all 106 nodes
Offset (hex)Bytes (hex)Meaning
13002 90230000000000 00i64 9104
1390F 0A 24010000 3001 0000map leaf, size 10: @124 → @130
1433C 637075txt "cpu"
14702 011D0000000000 00i64 7425
1500F 0A 43010000 4701 0000map leaf, size 10: @143 → @147
15A4C 77616C6Ctxt "wall"
15F02 081D0000000000 00i64 7432
1680F 0A 5A010000 5F01 0000map leaf, size 10: @15A → @15F
17207 12 21800000 3901 0000 50010000 6801 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @139 → @150 → @168
1847C 65786563757465txt "execute"
18C02 00000000000000 00i64 0
1950F 0A 84010000 8C01 0000map leaf, size 10: @184 → @18C
19F4C 726F7773txt "rows"
1A402 03000000000000 00i64 3
1AD0F 0A 9F010000 A401 0000map leaf, size 10: @19F → @1A4
1B74C 706C616Etxt "plan"
1BC02 6E010000000000 00i64 366
1C50F 0A B7010000 BC01 0000map leaf, size 10: @1B7 → @1BC
1CF3C 72756Etxt "run"
1D30F 0A CF010000 1201 0000map leaf, size 10: @1CF → @112
1DD07 12 01840000 AD01 0000 C5010000 D301 0000map branch, size 18, depth 1, slots 0, 10, 15: @1AD → @1C5 → @1D3
1EF5C 67726F7570txt "group"
1F502 00000000000000 00i64 0
1FE0F 0A EF010000 F501 0000map leaf, size 10: @1EF → @1F5
2087C 636F6D70696C65txt "compile"
21002 89000000000000 00i64 137
2190F 0A 08020000 1002 0000map leaf, size 10: @208 → @210
223AC 706172616D6574 657273txt "parameters"
22E0F 0A 23020000 B200 0000map leaf, size 10: @223 → @B2
23814 10 737461676573 5F636F6D706C6574 6564txt "stages_completed"
24A02 03000000000000 00i64 3
2530F 0A 38020000 4A02 0000map leaf, size 10: @238 → @24A
25D5C 6F72646572txt "order"
26302 00000000000000 00i64 0
26C0F 0A 5D020000 6302 0000map leaf, size 10: @25D → @263
27607 0E C0000000 5302 0000 6C020000map branch, size 14, depth 1, slots 6, 7: @253 → @26C
284EC 6172656E615F63 61706163697479txt "arena_capacity"
29302 00004000000000 00i64 4194304
29C0F 0A 84020000 9302 0000map leaf, size 10: @284 → @293
2A614 11 627564676574 5F757365645F6279 746573txt "budget_used_bytes"
2B902 D2270000000000 00i64 10194
2C20F 0A A6020000 B902 0000map leaf, size 10: @2A6 → @2B9
2CC07 0E 24000000 9C02 0000 C2020000map branch, size 14, depth 1, slots 2, 5: @29C → @2C2
2DAFC 6275646765745F 7265667573616C73txt "budget_refusals"
2EA02 00000000000000 00i64 0
2F30F 0A DA020000 EA02 0000map leaf, size 10: @2DA → @2EA
2FD4C 776F726Btxt "work"
30202 84110000000000 00i64 4484
30B0F 0A FD020000 0203 0000map leaf, size 10: @2FD → @302
31507 0E 88000000 F302 0000 0B030000map branch, size 14, depth 1, slots 3, 7: @2F3 → @30B
323FC 6D656D6F72795F 7265667573616C73txt "memory_refusals"
33302 00000000000000 00i64 0
33C0F 0A 23030000 3303 0000map leaf, size 10: @323 → @333
346CC 6275646765745F 6279746573txt "budget_bytes"
35302 00823E71020000 00i64 10489856512
35C0F 0A 46030000 5303 0000map leaf, size 10: @346 → @353
3665C 746F74616Ctxt "total"
36C0F 0A 66030000 7201 0000map leaf, size 10: @366 → @172
37614 11 627564676574 5F7065616B5F6279 746573txt "budget_peak_bytes"
38902 BB370000000000 00i64 14267
3920F 0A 76030000 8903 0000map leaf, size 10: @376 → @389
39C07 16 13040000 3C03 0000 5C030000 6C03 0000 92030000map branch, size 22, depth 1, slots 0, 1, 4, 10: @33C → @35C → @36C → @392
3B25C 7265747279txt "retry"
3B802 00000000000000 00i64 0
3C10F 0A B2030000 B803 0000map leaf, size 10: @3B2 → @3B8
3CB7C 72657472696573txt "retries"
3D302 00000000000000 00i64 0
3DC0F 0A CB030000 D303 0000map leaf, size 10: @3CB → @3D3
3E6CC 6D656D6F72795F 6279746573txt "memory_bytes"
3F302 6B170000000000 00i64 5995
3FC0F 0A E6030000 F303 0000map leaf, size 10: @3E6 → @3F3
406FC 6C6F61645F6465 66696E6974696F6Etxt "load_definition"
4160F 0A 06040000 5200 0000map leaf, size 10: @406 → @52
42007 0E 01100000 FC03 0000 16040000map branch, size 14, depth 1, slots 0, 12: @3FC → @416
42E07 36 FBDA0000 9501 0000 DD010000 FE01 0000 19020000 2E02 0000 76020000 CC02 0000 15030000 9C03 0000 C1030000 DC03 0000 20040000map branch, size 54, depth 0 (root), slots 0, 1, 3, 4, 5, 6, 7, 9, 11, 12, 14, 15: @195 → @1DD → @1FE → @219 → @22E → @276 → @2CC → @315 → @39C → @3C1 → @3DC → @420
Offset (hex)Bytes (hex)Meaning

A negative sub-tick Java duration rounds toward negative infinity

clojure65 B
{:page-size 0 :max-cost (java.time.Duration/ofNanos -1) :as-of 0}
TRON112 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
048C 6D61785F636F73 74txt "max_cost"
0D02 FFFFFFFFFFFFFF FFi64 -1
160F 0A 04000000 0D00 0000map leaf, size 10: @4 → @D
205C 61735F6F66txt "as_of"
2602 00000000000000 00i64 0
2F0F 0A 20000000 2600 0000map leaf, size 10: @20 → @26
399C 706167655F7369 7A65txt "page_size"
4302 00000000000000 00i64 0
4C0F 0A 39000000 4300 0000map leaf, size 10: @39 → @43
5607 12 28200000 1600 0000 2F000000 4C00 0000map branch, size 18, depth 0 (root), slots 3, 5, 13: @16 → @2F → @4C

Run with typed query options

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure240 B
(let [options {:page-size 2 :max-cost (java.time.Duration/ofSeconds 1) :as-of 0}]
  (with-open [definition (sd/parse query-text :tron)
              query (sd/query db definition)
              rows (sd/run query nil options)]
    options))
TRON112 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
048C 6D61785F636F73 74txt "max_cost"
0D02 80969800000000 00i64 10000000
160F 0A 04000000 0D00 0000map leaf, size 10: @4 → @D
205C 61735F6F66txt "as_of"
2602 00000000000000 00i64 0
2F0F 0A 20000000 2600 0000map leaf, size 10: @20 → @26
399C 706167655F7369 7A65txt "page_size"
4302 02000000000000 00i64 2
4C0F 0A 39000000 4300 0000map leaf, size 10: @39 → @43
5607 12 28200000 1600 0000 2F000000 4C00 0000map branch, size 18, depth 0 (root), slots 3, 5, 13: @16 → @2F → @4C

C exports: stardust_db_query_run, stardust_db_rows_error

close

clojure8 B
[handle]

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
handleQueryConsumed ownerRequiredThe query owner to release. Do not use it after this call.

Examples

Open an inline query and read its first page

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure144 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            rows (sd/run query)]
  (sd/next rows))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

C exports: stardust_db_query_release

next

clojure8 B
[handle]

Parameters

ParameterTypeOwnershipDefaultMeaning
handleRowsBorrowed for the callRequiredThe rows owner for this operation. Keep it alive during the call.

Errors

StatusWhen
:evaluation-failedthe page does not render
:closedthe rows is closed
:out-of-memorynative memory is exhausted

Notes

An empty array ends the cursor. Every page reads the snapshot selected by the run. Returned pages survive cursor and database closure.

Examples

Open an inline query and read its first page

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure144 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            rows (sd/run query)]
  (sd/next rows))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

C exports: stardust_db_rows_next, stardust_result_take_document, stardust_result_error, stardust_result_release

pages

clojure6 B
[rows]

Parameters

ParameterTypeOwnershipDefaultMeaning
rowsRowsBorrowed for the callRequiredThe rows owner for this operation. Keep it alive during the call.

Errors

StatusWhen
:evaluation-faileda page does not render
:closedthe rows is closed
:out-of-memorynative memory is exhausted

Notes

Pages are read lazily from the run's snapshot. Rust callers own each page. In other bindings, a page closes when iteration advances. Use next to retain an owned page. Close the cursor separately.

Examples

Iterate the pages of a query run

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure187 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            rows (sd/run query nil {:page-size 1})]
  (reduce (fn [n _page] (inc n)) 0 rows))
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 03000000000000 00i64 3

C exports: stardust_db_rows_next, stardust_result_take_document, stardust_result_error, stardust_result_release, stardust_document_root, stardust_document_read_many, stardust_document_release

all-pages

clojure6 B
[rows]

Parameters

ParameterTypeOwnershipDefaultMeaning
rowsRowsBorrowed for the callRequiredThe rows owner for this operation. Keep it alive during the call.

Errors

StatusWhen
:evaluation-faileda page does not render
:closedthe rows is closed
:out-of-memorynative memory is exhausted

Notes

The array contains rows, not page documents. Previously read pages are excluded. Memory grows with the remaining result. Use pages for bounded page-by-page processing. Close the cursor separately.

Examples

Read all remaining rows into one document

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure149 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            rows (sd/run query)]
  (sd/all-pages rows))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

C exports: stardust_db_rows_next, stardust_result_take_document, stardust_result_error, stardust_result_release, stardust_document_count, stardust_document_read_many, stardust_document_i64, stardust_document_f64, stardust_document_release, stardust_document_builder_create, stardust_document_builder_add_many, stardust_document_builder_seal, stardust_document_builder_release

close

clojure8 B
[handle]

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
handleRowsConsumed ownerRequiredThe rows owner to release. Do not use it after this call.

Examples

Open an inline query and read its first page

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure144 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            rows (sd/run query)]
  (sd/next rows))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

C exports: stardust_db_rows_release

subscribe

clojure7 B
[query]
clojure18 B
[query parameters]
clojure49 B
[query parameters {:keys [max-cost] :as options}]

Parameters

ParameterTypeOwnershipDefaultMeaning
queryQueryBorrowed for the callRequiredThe query owner for this operation. Keep it alive during the call.
parametersDocumentBorrowed for the callAbsent means no supplied parametersAn optional object of parameter values that merge-patches the definition's declared parameters. A parameter matched in the entity position of a fact clause takes an entity reference {#link id}, never the bare ID number: a commit returns IDs as numbers, so wrap one as {#link id}, or as the typed Link value where the binding has one, before passing it. A query run fails with entity_reference_expected when a bare number reaches that position. Projected and found entities also read back as {#link id}, so a typed field that receives one uses Link rather than a plain integer.
optionsrun-optionsValueAbsent selects operation defaultsThe operation's options record. See its field defaults.

Errors

StatusWhen
:invalid-definitionthe query or its callable definitions are invalid
:invalid-argumentthe parameters or subscription options are invalid
:closedthe query is closed
:out-of-memorynative memory is exhausted

Notes

The subscription copies its definition and parameters. Later definition edits do not change it. The page_size option is ignored.

Subscriptions register readiness callbacks automatically. Event waits use runtime notifications instead of blocking in the C ABI.

Query documents.

Examples

query/subscribe

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure305 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            subscription (sd/subscribe query)]
  (let [event (or (sd/next subscription (java.time.Duration/ofSeconds 5))
                  (throw (java.util.concurrent.TimeoutException.)))]
    (:result event)))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

Read the complete initial subscription event

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure259 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            subscription (sd/subscribe query)]
  (or (sd/next subscription (java.time.Duration/ofSeconds 5))
      (throw (java.util.concurrent.TimeoutException.))))
TRON217 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32
51AC 73757065727365 646564txt "superseded"
5C02 00000000000000 00i64 0
650F 0A 51000000 5C00 0000map leaf, size 10: @51 → @5C
6FBC 7472616E736163 74696F6Etxt "transaction"
7B02 04000000000000 00i64 4
840F 0A 6F000000 7B00 0000map leaf, size 10: @6F → @7B
8E6C 726573756C74txt "result"
950F 0A 8E000000 3C00 0000map leaf, size 10: @8E → @3C
9F8C 73657175656E63 65txt "sequence"
A802 01000000000000 00i64 1
B10F 0A 9F000000 A800 0000map leaf, size 10: @9F → @A8
BB07 16 00330000 6500 0000 84000000 9500 0000 B1000000map branch, size 22, depth 0 (root), slots 8, 9, 12, 13: @65 → @84 → @95 → @B1

C exports: stardust_db_query_subscribe, stardust_db_subscription_set_notify, stardust_db_subscription_error

next

clojure23 B
[subscription max-wait]

Parameters

ParameterTypeOwnershipDefaultMeaning
subscriptionSubscriptionBorrowed for the callRequiredThe subscription owner for this operation. Keep it alive during the call.
max-waitjava.time.DurationValueRequiredThe maximum wait. Zero checks once.

Errors

StatusWhen
:invalid-argumentmax_wait is negative
:cancelledthe subscription is cancelled or closed
:evaluation-faileda rerun of the query failed. Every later call reports this failure
:closedthe subscription is closed
:out-of-memorynative memory is exhausted

Notes

Each event replaces the entire result. superseded counts skipped computed results, not commits. Cancel, close and database close wake blocked waits. Windows rounds deadlines to milliseconds.

Examples

subscription/next

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure305 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            subscription (sd/subscribe query)]
  (let [event (or (sd/next subscription (java.time.Duration/ofSeconds 5))
                  (throw (java.util.concurrent.TimeoutException.)))]
    (:result event)))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

C exports: stardust_db_subscription_next, stardust_db_subscription_error, stardust_document_release

events

A subscription is reducible. Use reduce or into to consume events.

C exports: stardust_db_subscription_next, stardust_db_subscription_error

cancel

clojure14 B
[subscription]

Parameters

ParameterTypeOwnershipDefaultMeaning
subscriptionSubscriptionBorrowed for the callRequiredThe subscription owner for this operation. Keep it alive during the call.

Notes

Repeated cancellation is safe. Close the subscription separately to release its handle.

Examples

subscription/cancel

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure334 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            subscription (sd/subscribe query)]
  (let [event (or (sd/next subscription (java.time.Duration/ofSeconds 5))
                  (throw (java.util.concurrent.TimeoutException.)))]
    (sd/cancel subscription)
    (:result event)))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

C exports: stardust_db_subscription_cancel

close

clojure8 B
[handle]

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
handleSubscriptionConsumed ownerRequiredThe subscription owner to release. Do not use it after this call.

Examples

subscription/close

query-text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
clojure305 B
(with-open [definition (sd/parse query-text :tron)
            query (sd/query db definition)
            subscription (sd/subscribe query)]
  (let [event (or (sd/next subscription (java.time.Duration/ofSeconds 5))
                  (throw (java.util.concurrent.TimeoutException.)))]
    (:result event)))
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

C exports: stardust_db_subscription_release

run

clojure8 B
[handle]
clojure19 B
[handle parameters]
clojure50 B
[handle parameters {:keys [max-cost] :as options}]

Parameters

ParameterTypeOwnershipDefaultMeaning
handleMutationBorrowed for the callRequiredThe mutation owner for this operation. Keep it alive during the call.
parametersDocumentBorrowed for the callAbsent means no supplied parametersAn optional object of parameter values that merge-patches the definition's declared parameters. A parameter matched in the entity position of a fact clause takes an entity reference {#link id}, never the bare ID number: a commit returns IDs as numbers, so wrap one as {#link id}, or as the typed Link value where the binding has one, before passing it. A query run fails with entity_reference_expected when a bare number reaches that position. Projected and found entities also read back as {#link id}, so a typed field that receives one uses Link rather than a plain integer.
optionsrun-optionsValueAbsent selects operation defaultsThe operation's options record. See its field defaults.

Errors

StatusWhen
:invalid-definitionthe mutation selection or definition is invalid
:invalid-argumentthe parameters or run options are invalid
:schema-violationthe write breaks a schema
:conflictconcurrent writes prevent the commit
:rejecteda mutation target or write guard refuses the write
:unavailablethe patch sets stardust/history and no enabled plugin purges history
:evaluation-failedthe mutation fails
:closedthe mutation is closed
:out-of-memorynative memory is exhausted

Notes

Mutation documents.

Examples

mutation/run

birthday-text holds this document:

TRON221 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 6E616D65txt "name"
1C3C 416461txt "Ada"
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
6F3C 616765txt "age"
7302 25000000000000 00i64 37
7C0F 0A 6F000000 7300 0000map leaf, size 10: @6F → @73
862C 3F65txt "?e"
890F 0A 86000000 7C00 0000map leaf, size 10: @86 → @7C
935C 7175657279txt "query"
990F 0A 93000000 6100 0000map leaf, size 10: @93 → @61
A35C 7061746368txt "patch"
A90F 0A A3000000 8900 0000map leaf, size 10: @A3 → @89
B307 0E 40020000 9900 0000 A9000000map branch, size 14, depth 2, slots 6, 9: @99 → @A9
C107 0A 01000000 B300 0000map branch, size 10, depth 1, slots 0: @B3
CB07 0A 80000000 C100 0000map branch, size 10, depth 0 (root), slots 7: @C1
clojure116 B
(with-open [source (sd/parse birthday-text :tron)
            mutation (sd/mutation db source)]
  (sd/run mutation))
TRON179 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
040F 02map leaf, size 2
063C 696473txt "ids"
0A0F 0A 06000000 0400 0000map leaf, size 10: @6 → @4
146C 737461747573txt "status"
1B9C 636F6D6D697474 6564txt "committed"
250F 0A 14000000 1B00 0000map leaf, size 10: @14 → @1B
2F07 0E 02040000 0A00 0000 25000000map branch, size 14, depth 1, slots 1, 10: @A → @25
3DBC 7472616E736163 74696F6Etxt "transaction"
4902 05000000000000 00i64 5
520F 0A 3D000000 4900 0000map leaf, size 10: @3D → @49
5CCC 636F6D6D697474 65645F6174txt "committed_at"
6902 B8214F4035AD3F 00i64 17923367756571064
720F 0A 5C000000 6900 0000map leaf, size 10: @5C → @69
7C5C 6661637473txt "facts"
8202 01000000000000 00i64 1
8B0F 0A 7C000000 8200 0000map leaf, size 10: @7C → @82
9507 16 01460000 2F00 0000 52000000 7200 0000 8B000000map branch, size 22, depth 0 (root), slots 0, 9, 10, 14: @2F → @52 → @72 → @8B

Explain mutation execution

birthday-text holds this document:

TRON221 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 6E616D65txt "name"
1C3C 416461txt "Ada"
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
6F3C 616765txt "age"
7302 25000000000000 00i64 37
7C0F 0A 6F000000 7300 0000map leaf, size 10: @6F → @73
862C 3F65txt "?e"
890F 0A 86000000 7C00 0000map leaf, size 10: @86 → @7C
935C 7175657279txt "query"
990F 0A 93000000 6100 0000map leaf, size 10: @93 → @61
A35C 7061746368txt "patch"
A90F 0A A3000000 8900 0000map leaf, size 10: @A3 → @89
B307 0E 40020000 9900 0000 A9000000map branch, size 14, depth 2, slots 6, 9: @99 → @A9
C107 0A 01000000 B300 0000map branch, size 10, depth 1, slots 0: @B3
CB07 0A 80000000 C100 0000map branch, size 10, depth 0 (root), slots 7: @C1
clojure150 B
(with-open [source (sd/parse birthday-text :tron)
            mutation (sd/mutation db source)]
  (sd/explain (sd/run mutation nil {:explain? true})))
TRON606 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
004BC 6172656E615F62 79746573txt "arena_bytes"
01002 10090000000000 00i64 2320
0190F 0A 04000000 1000 0000map leaf, size 10: @4 → @10
0233C 637075txt "cpu"
02702 AE020000000000 00i64 686
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 AE020000000000 00i64 686
0480F 0A 3A000000 3F00 0000map leaf, size 10: @3A → @3F
05207 12 21800000 1900 0000 30000000 4800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @19 → @30 → @48
064BC 6172656E615F62 79746573txt "arena_bytes"
07002 00000000000000 00i64 0
0790F 0A 64000000 7000 0000map leaf, size 10: @64 → @70
0833C 637075txt "cpu"
08702 0F000000000000 00i64 15
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 1A000000000000 00i64 26
0A80F 0A 9A000000 9F00 0000map leaf, size 10: @9A → @9F
0B207 12 21800000 7900 0000 90000000 A800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @79 → @90 → @A8
0C4BC 6172656E615F62 79746573txt "arena_bytes"
0D002 50AB0000000000 00i64 43856
0D90F 0A C4000000 D000 0000map leaf, size 10: @C4 → @D0
0E33C 637075txt "cpu"
0E702 ED270000000000 00i64 10221
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 9FF00000000000 00i64 61599
1080F 0A FA000000 FF00 0000map leaf, size 10: @FA → @FF
11207 12 21800000 D900 0000 F0000000 0801 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @D9 → @F0 → @108
124BC 6172656E615F62 79746573txt "arena_bytes"
Show all 58 nodes
Offset (hex)Bytes (hex)Meaning
13002 60B40000000000 00i64 46176
1390F 0A 24010000 3001 0000map leaf, size 10: @124 → @130
1433C 637075txt "cpu"
14702 332B0000000000 00i64 11059
1500F 0A 43010000 4701 0000map leaf, size 10: @143 → @147
15A4C 77616C6Ctxt "wall"
15F02 F4F30000000000 00i64 62452
1680F 0A 5A010000 5F01 0000map leaf, size 10: @15A → @15F
17207 12 21800000 3901 0000 50010000 6801 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @139 → @150 → @168
1843C 72756Etxt "run"
1880F 0A 84010000 1201 0000map leaf, size 10: @184 → @112
192AC 706172616D6574 657273txt "parameters"
19D0F 0A 92010000 B200 0000map leaf, size 10: @192 → @B2
1A714 10 737461676573 5F636F6D706C6574 6564txt "stages_completed"
1B902 03000000000000 00i64 3
1C20F 0A A7010000 B901 0000map leaf, size 10: @1A7 → @1B9
1CCEC 6172656E615F63 61706163697479txt "arena_capacity"
1DB02 00004000000000 00i64 4194304
1E40F 0A CC010000 DB01 0000map leaf, size 10: @1CC → @1DB
1EE5C 746F74616Ctxt "total"
1F40F 0A EE010000 7201 0000map leaf, size 10: @1EE → @172
1FE8C 617474656D7074 73txt "attempts"
20702 01000000000000 00i64 1
2100F 0A FE010000 0702 0000map leaf, size 10: @1FE → @207
21AFC 6C6F61645F6465 66696E6974696F6Etxt "load_definition"
22A0F 0A 1A020000 5200 0000map leaf, size 10: @21A → @52
23407 22 E2A80000 8801 0000 9D010000 C201 0000 E4010000 F401 0000 10020000 2A02 0000map branch, size 34, depth 0 (root), slots 1, 5, 6, 7, 11, 13, 15: @188 → @19D → @1C2 → @1E4 → @1F4 → @210 → @22A
Offset (hex)Bytes (hex)Meaning

C exports: stardust_db_mutation_run, stardust_db_result_commit_info, stardust_result_error, stardust_result_release

close

clojure8 B
[handle]

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
handleMutationConsumed ownerRequiredThe mutation owner to release. Do not use it after this call.

Examples

mutation/close

birthday-text holds this document:

TRON221 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 6E616D65txt "name"
1C3C 416461txt "Ada"
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
6F3C 616765txt "age"
7302 25000000000000 00i64 37
7C0F 0A 6F000000 7300 0000map leaf, size 10: @6F → @73
862C 3F65txt "?e"
890F 0A 86000000 7C00 0000map leaf, size 10: @86 → @7C
935C 7175657279txt "query"
990F 0A 93000000 6100 0000map leaf, size 10: @93 → @61
A35C 7061746368txt "patch"
A90F 0A A3000000 8900 0000map leaf, size 10: @A3 → @89
B307 0E 40020000 9900 0000 A9000000map branch, size 14, depth 2, slots 6, 9: @99 → @A9
C107 0A 01000000 B300 0000map branch, size 10, depth 1, slots 0: @B3
CB07 0A 80000000 C100 0000map branch, size 10, depth 0 (root), slots 7: @C1
clojure116 B
(with-open [source (sd/parse birthday-text :tron)
            mutation (sd/mutation db source)]
  (sd/run mutation))
TRON179 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
040F 02map leaf, size 2
063C 696473txt "ids"
0A0F 0A 06000000 0400 0000map leaf, size 10: @6 → @4
146C 737461747573txt "status"
1B9C 636F6D6D697474 6564txt "committed"
250F 0A 14000000 1B00 0000map leaf, size 10: @14 → @1B
2F07 0E 02040000 0A00 0000 25000000map branch, size 14, depth 1, slots 1, 10: @A → @25
3DBC 7472616E736163 74696F6Etxt "transaction"
4902 05000000000000 00i64 5
520F 0A 3D000000 4900 0000map leaf, size 10: @3D → @49
5CCC 636F6D6D697474 65645F6174txt "committed_at"
6902 42F53E4035AD3F 00i64 17923367755511106
720F 0A 5C000000 6900 0000map leaf, size 10: @5C → @69
7C5C 6661637473txt "facts"
8202 01000000000000 00i64 1
8B0F 0A 7C000000 8200 0000map leaf, size 10: @7C → @82
9507 16 01460000 2F00 0000 52000000 7200 0000 8B000000map branch, size 22, depth 0 (root), slots 0, 9, 10, 14: @2F → @52 → @72 → @8B

C exports: stardust_db_mutation_release

merge-patch

clojure10 B
[db patch]
clojure18 B
[db patch options]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
patchDocumentBorrowed for the callRequiredAn entity-keyed native patch. Temporary names use #_name. #_tx holds metadata and an optional stardust/checkAndSet map from entity IDs to expected transactions. Positive expectations match exact last-touch transactions; zero requires no current facts. Conditions are consumed and checked atomically, including for no-ops.
optionsmapValue{}Binding options map. The :library key selects the loaded native library. Omission uses the binding's default library. Optional explain output. This record contains explain output for merge_patch.

Errors

StatusWhen
:invalid-commit-timethe #_tx commit time is not later than the last commit
:conflictan entity revision check fails or a concurrent writer prevents the commit; a revision mismatch reports the entity and expected and actual revisions
:rejectedthe database refuses the patch; the code and diagnostic path name the reason and key
:unavailablethe patch sets stardust/history and no enabled plugin purges history
:invalid-argumentthe patch is not an entity-keyed object, or a link names an ID outside the user entity range
:closedthe database is closed
:out-of-memorynative memory is exhausted

Notes

Patch documents.

Examples

database/merge_patch

seed-text holds this document:

TRON449 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0043C 616765txt "age"
00802 24000000000000 00i64 36
0110F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
01B4C 726F6C65txt "role"
0208C 656E67696E6565 72txt "engineer"
0290F 0A 1B000000 2000 0000map leaf, size 10: @1B → @20
0334C 6E616D65txt "name"
0383C 416461txt "Ada"
03C0F 0A 33000000 3800 0000map leaf, size 10: @33 → @38
04607 12 00910000 1100 0000 29000000 3C00 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @11 → @29 → @3C
0585C 236C696E6Btxt "#link"
05E5C 235F616461txt "#_ada"
0640F 0A 58000000 5E00 0000map leaf, size 10: @58 → @5E
06E3C 616765txt "age"
07202 29000000000000 00i64 41
07B0F 0A 6E000000 7200 0000map leaf, size 10: @6E → @72
0856C 6D656E746F72txt "mentor"
08C0F 0A 85000000 6400 0000map leaf, size 10: @85 → @64
0964C 726F6C65txt "role"
09B8C 656E67696E6565 72txt "engineer"
0A40F 0A 96000000 9B00 0000map leaf, size 10: @96 → @9B
0AE4C 6E616D65txt "name"
0B33C 426F62txt "Bob"
0B70F 0A AE000000 B300 0000map leaf, size 10: @AE → @B3
0C107 16 00990000 7B00 0000 8C000000 A400 0000 B7000000map branch, size 22, depth 0 (root), slots 8, 11, 12, 15: @7B → @8C → @A4 → @B7
0D73C 616765txt "age"
0DB02 1D000000000000 00i64 29
0E40F 0A D7000000 DB00 0000map leaf, size 10: @D7 → @DB
0EE4C 726F6C65txt "role"
0F38C 64657369676E65 72txt "designer"
0FC0F 0A EE000000 F300 0000map leaf, size 10: @EE → @F3
1064C 6E616D65txt "name"
10B2C 4379txt "Cy"
10E0F 0A 06010000 0B01 0000map leaf, size 10: @106 → @10B
11807 12 00910000 E400 0000 FC000000 0E01 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @E4 → @FC → @10E
12A6C 617574686F72txt "author"
1315C 736D6F6B65txt "smoke"
1370F 0A 2A010000 3101 0000map leaf, size 10: @12A → @131
1416C 726561736F6Etxt "reason"
1484C 73656564txt "seed"
14D0F 0A 41010000 4801 0000map leaf, size 10: @141 → @148
15707 0E 40080000 3701 0000 4D010000map branch, size 14, depth 0 (root), slots 6, 11: @137 → @14D
1654C 235F7478txt "#_tx"
16A0F 0A 65010000 5701 0000map leaf, size 10: @165 → @157
1744C 235F6379txt "#_cy"
1790F 0A 74010000 1801 0000map leaf, size 10: @174 → @118
1835C 235F626F62txt "#_bob"
1890F 0A 83010000 C100 0000map leaf, size 10: @183 → @C1
1935C 235F616461txt "#_ada"
1990F 0A 93010000 4600 0000map leaf, size 10: @193 → @46
1A307 16 88210000 6A01 0000 79010000 8901 0000 99010000map branch, size 22, depth 0 (root), slots 3, 7, 8, 13: @16A → @179 → @189 → @199
clojure74 B
(with-open [patch (sd/parse seed-text :tron)]
  (sd/merge-patch db patch))
TRON269 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0044C 235F6379txt "#_cy"
00902 01000000000000 00i64 1
0120F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
01C5C 235F626F62txt "#_bob"
02202 02000000000000 00i64 2
02B0F 0A 1C000000 2200 0000map leaf, size 10: @1C → @22
0355C 235F616461txt "#_ada"
03B02 03000000000000 00i64 3
0440F 0A 35000000 3B00 0000map leaf, size 10: @35 → @3B
04E07 12 80210000 1200 0000 2B000000 4400 0000map branch, size 18, depth 0 (root), slots 7, 8, 13: @12 → @2B → @44
0603C 696473txt "ids"
0640F 0A 60000000 4E00 0000map leaf, size 10: @60 → @4E
06E6C 737461747573txt "status"
0759C 636F6D6D697474 6564txt "committed"
07F0F 0A 6E000000 7500 0000map leaf, size 10: @6E → @75
08907 0E 02040000 6400 0000 7F000000map branch, size 14, depth 1, slots 1, 10: @64 → @7F
097BC 7472616E736163 74696F6Etxt "transaction"
0A302 04000000000000 00i64 4
0AC0F 0A 97000000 A300 0000map leaf, size 10: @97 → @A3
0B6CC 636F6D6D697474 65645F6174txt "committed_at"
0C302 9710BC3F35AD3F 00i64 17923367746932887
0CC0F 0A B6000000 C300 0000map leaf, size 10: @B6 → @C3
0D65C 6661637473txt "facts"
0DC02 0C000000000000 00i64 12
0E50F 0A D6000000 DC00 0000map leaf, size 10: @D6 → @DC
0EF07 16 01460000 8900 0000 AC000000 CC00 0000 E5000000map branch, size 22, depth 0 (root), slots 0, 9, 10, 14: @89 → @AC → @CC → @E5

Explain patch validation and commit

seed-text holds this document:

TRON449 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0043C 616765txt "age"
00802 24000000000000 00i64 36
0110F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
01B4C 726F6C65txt "role"
0208C 656E67696E6565 72txt "engineer"
0290F 0A 1B000000 2000 0000map leaf, size 10: @1B → @20
0334C 6E616D65txt "name"
0383C 416461txt "Ada"
03C0F 0A 33000000 3800 0000map leaf, size 10: @33 → @38
04607 12 00910000 1100 0000 29000000 3C00 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @11 → @29 → @3C
0585C 236C696E6Btxt "#link"
05E5C 235F616461txt "#_ada"
0640F 0A 58000000 5E00 0000map leaf, size 10: @58 → @5E
06E3C 616765txt "age"
07202 29000000000000 00i64 41
07B0F 0A 6E000000 7200 0000map leaf, size 10: @6E → @72
0856C 6D656E746F72txt "mentor"
08C0F 0A 85000000 6400 0000map leaf, size 10: @85 → @64
0964C 726F6C65txt "role"
09B8C 656E67696E6565 72txt "engineer"
0A40F 0A 96000000 9B00 0000map leaf, size 10: @96 → @9B
0AE4C 6E616D65txt "name"
0B33C 426F62txt "Bob"
0B70F 0A AE000000 B300 0000map leaf, size 10: @AE → @B3
0C107 16 00990000 7B00 0000 8C000000 A400 0000 B7000000map branch, size 22, depth 0 (root), slots 8, 11, 12, 15: @7B → @8C → @A4 → @B7
0D73C 616765txt "age"
0DB02 1D000000000000 00i64 29
0E40F 0A D7000000 DB00 0000map leaf, size 10: @D7 → @DB
0EE4C 726F6C65txt "role"
0F38C 64657369676E65 72txt "designer"
0FC0F 0A EE000000 F300 0000map leaf, size 10: @EE → @F3
1064C 6E616D65txt "name"
10B2C 4379txt "Cy"
10E0F 0A 06010000 0B01 0000map leaf, size 10: @106 → @10B
11807 12 00910000 E400 0000 FC000000 0E01 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @E4 → @FC → @10E
12A6C 617574686F72txt "author"
1315C 736D6F6B65txt "smoke"
1370F 0A 2A010000 3101 0000map leaf, size 10: @12A → @131
1416C 726561736F6Etxt "reason"
1484C 73656564txt "seed"
14D0F 0A 41010000 4801 0000map leaf, size 10: @141 → @148
15707 0E 40080000 3701 0000 4D010000map branch, size 14, depth 0 (root), slots 6, 11: @137 → @14D
1654C 235F7478txt "#_tx"
16A0F 0A 65010000 5701 0000map leaf, size 10: @165 → @157
1744C 235F6379txt "#_cy"
1790F 0A 74010000 1801 0000map leaf, size 10: @174 → @118
1835C 235F626F62txt "#_bob"
1890F 0A 83010000 C100 0000map leaf, size 10: @183 → @C1
1935C 235F616461txt "#_ada"
1990F 0A 93010000 4600 0000map leaf, size 10: @193 → @46
1A307 16 88210000 6A01 0000 79010000 8901 0000 99010000map branch, size 22, depth 0 (root), slots 3, 7, 8, 13: @16A → @179 → @189 → @199
clojure104 B
(with-open [patch (sd/parse seed-text :tron)]
  (sd/explain (sd/merge-patch db patch {:explain? true})))
TRON461 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
004BC 6172656E615F62 79746573txt "arena_bytes"
01002 180C0000000000 00i64 3096
0190F 0A 04000000 1000 0000map leaf, size 10: @4 → @10
0233C 637075txt "cpu"
02702 070A0000000000 00i64 2567
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 130A0000000000 00i64 2579
0480F 0A 3A000000 3F00 0000map leaf, size 10: @3A → @3F
05207 12 21800000 1900 0000 30000000 4800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @19 → @30 → @48
064BC 6172656E615F62 79746573txt "arena_bytes"
07002 481F0000000000 00i64 8008
0790F 0A 64000000 7000 0000map leaf, size 10: @64 → @70
0833C 637075txt "cpu"
08702 54020000000000 00i64 596
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 04880000000000 00i64 34820
0A80F 0A 9A000000 9F00 0000map leaf, size 10: @9A → @9F
0B207 12 21800000 7900 0000 90000000 A800 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @79 → @90 → @A8
0C4BC 6172656E615F62 79746573txt "arena_bytes"
0D002 6E2B0000000000 00i64 11118
0D90F 0A C4000000 D000 0000map leaf, size 10: @C4 → @D0
0E33C 637075txt "cpu"
0E702 120D0000000000 00i64 3346
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 CF920000000000 00i64 37583
1080F 0A FA000000 FF00 0000map leaf, size 10: @FA → @FF
11207 12 21800000 D900 0000 F0000000 0801 0000map branch, size 18, depth 0 (root), slots 0, 5, 15: @D9 → @F0 → @108
12414 10 737461676573 5F636F6D706C6574 6564txt "stages_completed"
13602 02000000000000 00i64 2
13F0F 0A 24010000 3601 0000map leaf, size 10: @124 → @136
149EC 6172656E615F63 61706163697479txt "arena_capacity"
15802 00004000000000 00i64 4194304
1610F 0A 49010000 5801 0000map leaf, size 10: @149 → @158
16B5C 746F74616Ctxt "total"
1710F 0A 6B010000 1201 0000map leaf, size 10: @16B → @112
17B6C 636F6D6D6974txt "commit"
1820F 0A 7B010000 B200 0000map leaf, size 10: @17B → @B2
18CAC 636F70795F7061 746368txt "copy_patch"
1970F 0A 8C010000 5200 0000map leaf, size 10: @18C → @52
1A107 0E 08100000 8201 0000 97010000map branch, size 14, depth 1, slots 3, 12: @182 → @197
1AF07 16 C0880000 3F01 0000 61010000 7101 0000 A1010000map branch, size 22, depth 0 (root), slots 6, 7, 11, 15: @13F → @161 → @171 → @1A1

Refuse a metadata-only transaction

patch-text holds this document:

TRON46 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 617574686F72txt "author"
0B1C 78txt "x"
0D0F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
174C 235F7478txt "#_tx"
1C0F 0A 17000000 0D00 0000map leaf, size 10: @17 → @D
clojure75 B
(with-open [patch (sd/parse patch-text :tron)]
  (sd/merge-patch db patch))
TRON263 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0046C 737461747573txt "status"
00B8C 72656A65637465 64txt "rejected"
0140F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
01E6C 656E74697479txt "entity"
02500nil
0260F 0A 1E000000 2500 0000map leaf, size 10: @1E → @25
0307C 6D657373616765txt "message"
03814 37 612070617463 68206F66206F6E6C 7920235F74782069 7320726566757365 643A20235F747820 616E6E6F74617465 7320612077726974 65txt "a patch of only #_tx is …"
0710F 0A 30000000 3800 0000map leaf, size 10: @30 → @38
07B07 0E 08020000 2600 0000 71000000map branch, size 14, depth 1, slots 3, 9: @26 → @71
0894C 70617468txt "path"
08E4C 235F7478txt "#_tx"
0930F 0A 89000000 8E00 0000map leaf, size 10: @89 → @8E
09D5C 6669656C64txt "field"
0A300nil
0A40F 0A 9D000000 A300 0000map leaf, size 10: @9D → @A3
0AE4C 636F6465txt "code"
0B314 10 7472616E7361 6374696F6E5F6F6E 6C79txt "transaction_only"
0C50F 0A AE000000 B300 0000map leaf, size 10: @AE → @B3
0CF6C 6F6666736574txt "offset"
0D600nil
0D70F 0A CF000000 D600 0000map leaf, size 10: @CF → @D6
0E107 1E 51620000 1400 0000 7B000000 9300 0000 A4000000 C500 0000 D7000000map branch, size 30, depth 0 (root), slots 0, 4, 6, 9, 13, 14: @14 → @7B → @93 → @A4 → @C5 → @D7

Refuse a repeated commit time

future-text holds this document:

TRON145 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 01000000000000 00i64 1
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
194C 23757463txt "#utc"
1E14 14 323230302D30 312D30315430303A 30303A30305Atxt "2200-01-01T00:00:00Z"
340F 0A 19000000 1E00 0000map leaf, size 10: @19 → @1E
3E14 14 737461726475 73742F636F6D6D69 747465644174txt "stardust/committedAt"
540F 0A 3E000000 3400 0000map leaf, size 10: @3E → @34
5E4C 235F7478txt "#_tx"
630F 0A 5E000000 5400 0000map leaf, size 10: @5E → @54
6D3C 235F64txt "#_d"
710F 0A 6D000000 0F00 0000map leaf, size 10: @6D → @F
7B07 0E 08010000 6300 0000 71000000map branch, size 14, depth 0 (root), slots 3, 8: @63 → @71

older-text holds this document:

TRON145 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 78txt "x"
0602 02000000000000 00i64 2
0F0F 0A 04000000 0600 0000map leaf, size 10: @4 → @6
194C 23757463txt "#utc"
1E14 14 323230302D30 312D30315430303A 30303A30305Atxt "2200-01-01T00:00:00Z"
340F 0A 19000000 1E00 0000map leaf, size 10: @19 → @1E
3E14 14 737461726475 73742F636F6D6D69 747465644174txt "stardust/committedAt"
540F 0A 3E000000 3400 0000map leaf, size 10: @3E → @34
5E4C 235F7478txt "#_tx"
630F 0A 5E000000 5400 0000map leaf, size 10: @5E → @54
6D3C 235F65txt "#_e"
710F 0A 6D000000 0F00 0000map leaf, size 10: @6D → @F
7B07 0E 08010000 6300 0000 71000000map branch, size 14, depth 0 (root), slots 3, 8: @63 → @71
clojure152 B
(with-open [future (sd/parse future-text :tron)
            older (sd/parse older-text :tron)]
  (sd/merge-patch db future)
  (sd/merge-patch db older))
TRON290 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0046C 737461747573txt "status"
00B14 13 696E76616C69 645F636F6D6D6974 5F74696D65txt "invalid_commit_time"
0200F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
02A6C 656E74697479txt "entity"
03100nil
0320F 0A 2A000000 3100 0000map leaf, size 10: @2A → @31
03C7C 6D657373616765txt "message"
04414 47 737461726475 73742F636F6D6D69 747465644174206D 7573742062652073 74726963746C7920 6E65776572207468 616E20746865206C 617465737420636F 6D6D69742074696D 65txt "stardust/committedAt mus…"
08D0F 0A 3C000000 4400 0000map leaf, size 10: @3C → @44
09707 0E 08020000 3200 0000 8D000000map branch, size 14, depth 1, slots 3, 9: @32 → @8D
0A54C 70617468txt "path"
0AA00nil
0AB0F 0A A5000000 AA00 0000map leaf, size 10: @A5 → @AA
0B55C 6669656C64txt "field"
0BB00nil
0BC0F 0A B5000000 BB00 0000map leaf, size 10: @B5 → @BB
0C64C 636F6465txt "code"
0CB14 13 696E76616C69 645F636F6D6D6974 5F74696D65txt "invalid_commit_time"
0E00F 0A C6000000 CB00 0000map leaf, size 10: @C6 → @CB
0EA6C 6F6666736574txt "offset"
0F100nil
0F20F 0A EA000000 F100 0000map leaf, size 10: @EA → @F1
0FC07 1E 51620000 2000 0000 97000000 AB00 0000 BC000000 E000 0000 F2000000map branch, size 30, depth 0 (root), slots 0, 4, 6, 9, 13, 14: @20 → @97 → @AB → @BC → @E0 → @F2

C exports: stardust_db_merge_patch, stardust_db_result_commit_info, stardust_result_error, stardust_result_release

indexes-sync

clojure13 B
[db max-wait]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
max-waitjava.time.DurationValueRequiredThe maximum wait. Zero checks once.

Errors

StatusWhen
:invalid-argumentmax_wait is negative
:timeoutmax_wait passed first
:closedthe database is closed

Notes

An index that cannot be built does not hold this wait.

Examples

Wait for the exact indexes of the stored queries

clojure94 B
(sd/indexes-sync db (java.time.Duration/ofSeconds 5))
(sd/definitions db :queries "people/.*")
TRON40 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
04EC 70656F706C652F 62795F726F6C65txt "people/by_role"
130E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4

C exports: stardust_db_indexes_sync

bulk-begin

clojure4 B
[db]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.

Errors

StatusWhen
:invalid-argumenta bulk build is already in progress on the database
:closedthe database is closed
:out-of-memorynative memory is exhausted

Notes

On a database with existing facts, each added patch commits immediately and the summary reports fallback true. Closing the database drops an unfinished build.

Examples

Start a bulk build and drop it

clojure37 B
(sd/bulk-begin db)
(sd/bulk-abort db)

C exports: stardust_db_bulk_begin

bulk-add

clojure10 B
[db patch]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
patchDocumentBorrowed for the callRequiredOne borrowed entity-keyed merge-patch document, as merge_patch takes it. Temporary names use #_name and are scoped to this patch. Transaction metadata uses #_tx. The document is borrowed only until the call returns.

Errors

StatusWhen
:invalid-argumentno bulk build is in progress
:rejectedthe database refuses the patch; the build has failed and later adds report the same status
:closedthe database is closed
:out-of-memorynative memory is exhausted

Notes

Patches retain add order. Entity and field order within a patch does not matter. Temporary names resolve within one patch. The call waits for space within the build's memory budget. After failure, use finish for its diagnostic or abort for cleanup.

Patch documents.

Examples

Queue patches in commit order

clojure325 B
;; The first entity of an empty database is 1, so the second patch updates it.
(sd/bulk-begin db)
(with-open [patch (sd/parse "{\"#_ada\":{\"name\":\"Ada\"}}" :json)]
  (sd/bulk-add db patch))
(with-open [patch (sd/parse "{\"1\":{\"title\":\"Countess\"}}" :json)]
  (sd/bulk-add db patch))
(with-open [_ (sd/bulk-finish db)])

C exports: stardust_db_bulk_add

bulk-finish

clojure4 B
[db]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.

Errors

StatusWhen
:invalid-argumentno bulk build is in progress
:rejectedthe database refuses a patch; an initial build publishes nothing and fallback keeps earlier commits
:conflictanother write committed to the database during the build
:closedthe database is closed
:out-of-memorynative memory is exhausted

Notes

Finish ends the build even on failure. An initial build publishes all patches or none. Fallback keeps patches already committed.

The summary contains:

FieldMeaning
statuscommitted, or no_change when nothing was written
patches, transactions, facts, entitiesLoad counts
firstTransaction, lastTransactionAssigned transaction range
fallbackWhether patches committed individually
threadsWorker count
tempBytesTemporary run bytes
memoryBytes, memoryPeakBytesReserved memory share and its peak use
phasesparse, assign, rows, updates, spill, build and commit timings, each with wallNs and cpuNs

The memory budget covers build allocations. It excludes operating-system file cache and the process baseline.

Examples

Load patches with one commit and read the summary

clojure408 B
;; bulk-load does the same for a sequence of patches, aborting on failure.
(sd/bulk-begin db)
(with-open [patch (sd/parse "{\"#_ada\":{\"name\":\"Ada\",\"title\":\"Countess\"}}" :json)]
  (sd/bulk-add db patch))
;; Finish ends the build also when it fails.
(with-open [summary (sd/bulk-finish db)]
  ;; status, patches, transactions, facts, entities and phase timings
  (:transactions (sd/to-value summary)))

C exports: stardust_db_bulk_finish, stardust_result_take_document, stardust_result_error, stardust_result_release

bulk-abort

clojure4 B
[db]

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.

Notes

Abort preserves patches already committed in fallback mode. It is safe without a build or after database closure.

Examples

Drop a bulk build without writing it

clojure190 B
(sd/bulk-begin db)
(with-open [patch (sd/parse "{\"#_ada\":{\"name\":\"Ada\"}}" :json)]
  (sd/bulk-add db patch))
;; Abort writes nothing; without a build it does nothing.
(sd/bulk-abort db)

C exports: stardust_db_bulk_abort

run_options

This record supplies options for query and mutation run. Zero selects each default. Mutations use DB_Write_Options, whose fields are a subset.

FieldTypeUnitRangeMeaning
page_sizeCountCountHost type rangeRows per page. 0 selects the default page size. Queries only.
max_costDurationHost duration (100 ns ticks at the ABI)Tick rangeThread CPU duration limit. 0 selects the engine’s dynamic budget.
as_ofIntegerNoneHost type rangeA positive transaction runs a stored definition as of that transaction.

commit

This record contains the result of mutation run, merge_patch and patch_definition.

FieldTypeUnitRangeAbsentMeaning
statusCommit-StatusNoneHost type range——
transactionIntegerNoneHost type range—Zero when nothing was written.
factsIntegerCountHost type range——
committed_atInstantUTC instant (100 ns ticks since the Unix epoch at the ABI)Tick rangenilRecorded commit time as a UTC instant. The call measures this value. Independent calls can differ.
idsId-MapNoneHost type range—Maps each #_name of a merge patch to its entity ID number. Wrap an ID as {#link id}, or as the typed Link value where the binding has one, to pass it as an entity reference.

event

This record contains the result of subscription next.

FieldTypeUnitMeaning
sequenceIntegerCountEvent number. Event 1 is the initial result.
supersededIntegerCountIntermediate computed results skipped by this subscription since its previous event. Zero for its first event. The delivered result replaces them in full. This value counts neither commits nor changed rows.
transactionIntegerNoneTransaction the result was computed at.
resultDocumentNoneThe full query result. The event owns it and the consumer closes it.