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
rust319 B
let birthday = stardust::parse(birthday_text, Format::TRON)?;
db.mutation(&birthday)?.run(None, &RunOptions::default(), None)?;
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut rows = query.run(None, &RunOptions::default(), None)?;
let result = rows.all_pages()?;
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
Database::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.
Database::queryqueryOpen an owned query from a path or an inline definition.
Database::mutationmutationOpen an owned mutation from a path or an inline definition.
Query::runrowsRun the query and return an owned row cursor.
Query::closenoneRelease the query handle.
Rows::next_pagedocumentRead the next page as an owned document.
Rows::pagespagesrows.pages() iterates the non-empty pages of the cursor.
Rows::all_pagesdocumentrows.all_pages() reads every remaining page into one owned array document.
Rows::closenoneRelease the rows handle.
Query::subscribesubscriptionquery.subscribe(parameters, options) opens an owned live subscription.
Subscription::nexteventWait for the next live event.
Subscription::eventseventssubscription.events() delivers events in order until the subscription is cancelled, closes or fails.
Subscription::cancelnonesubscription.cancel() ends the subscription.
Subscription::closenoneRelease the subscription handle.
Mutation::runcommitRun the mutation and return commit information.
Mutation::closenoneRelease the mutation handle.
Database::merge_patchcommitdatabase.merge_patch(patch) applies an entity-keyed patch document in one transaction and returns commit information.
Database::indexes_syncnonedatabase.indexes_sync(max_wait) waits until the database built every exact index that earlier definition commits and inline runs ask for.
Database::bulk_beginnonedatabase.bulk_begin() starts a bulk build of data merge patches held by the database.
Database::bulk_addnonedatabase.bulk_add(patch) copies and queues one merge-patch document in the bulk build.
Database::bulk_finishdocumentdatabase.bulk_finish() publishes the bulk build with one commit, ends it and returns an owned summary document.
Database::bulk_abortnonedatabase.bulk_abort() drops the bulk build in progress without writing it.

Database::read_entity

rust93 B
pub fn read_entity(&self, entity: i64, max_depth: i64, max_entities: i64) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
entityi64ValueRequiredThe decimal user entity ID.
max_depthi64ValueAbsentLink hops to expand along each path, 0 through 32. 0, the default, leaves every link a {#link id} reference.
max_entitiesi64ValueAbsentThe 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
Status::INVALID_ARGUMENTthe entity ID is outside the user entity range, max_depth is negative or above 32, or max_entities is negative
Status::CLOSEDthe database is closed
Status::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

rust38 B
let result = db.read_entity(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

Database::query

rust71 B
pub fn query<'a>(&self, source: impl Into<Source<'a>>) -> Result<Query>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
sourceimpl Into<Source<'a>>ValueRequiredAn inline native definition or a stored definition path.

Errors

StatusWhen
Status::NOT_FOUNDno definition is stored at the path
Status::INVALID_DEFINITIONthe definition is invalid
Status::CLOSEDthe database is closed
Status::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
rust191 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut rows = query.run(None, &RunOptions::default(), None)?;
let result = rows.next_page()?;
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

query_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
rust102 B
let definition = stardust::parse(query_text, Format::TRON)?;
let result = db.query(&definition).err();
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

rust46 B
let result = db.query("people/missing").err();
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

Database::mutation

rust77 B
pub fn mutation<'a>(&self, source: impl Into<Source<'a>>) -> Result<Mutation>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
sourceimpl Into<Source<'a>>ValueRequiredAn inline native definition or a stored definition path.

Errors

StatusWhen
Status::NOT_FOUNDno definition is stored at the path
Status::INVALID_DEFINITIONthe definition is invalid
Status::CLOSEDthe database is closed
Status::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
rust161 B
let source = stardust::parse(birthday_text, Format::TRON)?;
let mutation = db.mutation(&source)?;
let result = mutation.run(None, &RunOptions::default(), None)?;
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 FD612F3C35AD3F 00i64 17923367687381501
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

Query::run

rust161 B
pub fn run(
        &self,
        parameters: Option<&Document>,
        options: &RunOptions,
        explain: Option<&mut QueryExplain>,
    ) -> Result<Rows>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe query owner for this operation. Keep it alive during the call.
parametersOption<&Document>Borrowed 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.
options&RunOptionsValueRequired options record. See field defaultsThe operation's options record. See its field defaults.
explainOption<&mut QueryExplain>Caller-owned outputAbsent skips explain outputOptional explain output. This record contains explain output for query run. The compile, plan, execute, group and order fields divide the wall time of run into stages.

Errors

StatusWhen
Status::NOT_FOUNDthe stored query definition was deleted
Status::INVALID_DEFINITIONthe loaded query definition is invalid
Status::INVALID_ARGUMENTthe parameters or run options are invalid
Status::EVALUATION_FAILEDthe query fails or exceeds max_cost
Status::CLOSEDthe query is closed
Status::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
rust191 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut rows = query.run(None, &RunOptions::default(), None)?;
let result = rows.next_page()?;
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

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

boundary_text holds this document:

TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 FFFFFFFFFFFFFF 7Fi64 9223372036854775807
rust396 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let boundary = stardust::parse(boundary_text, Format::TRON)?;
let seconds = boundary.i64(boundary.root()?)? as u64;
let options = RunOptions { page_size: 2, max_cost: std::time::Duration::from_secs(seconds), ..Default::default() };
let _rows = query.run(None, &options, None)?;
let result = 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

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

boundary_text holds this document:

TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 63000000000000 00i64 99
rust393 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let boundary = stardust::parse(boundary_text, Format::TRON)?;
let nanos = boundary.i64(boundary.root()?)? as u64;
let options = RunOptions { page_size: 2, max_cost: std::time::Duration::from_nanos(nanos), ..Default::default() };
let _rows = query.run(None, &options, None)?;
let result = 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
rust245 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut explain = stardust::QueryExplain::default();
let _rows = query.run(None, &RunOptions::default(), Some(&mut explain))?;
let result = explain;
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 9B030000000000 00i64 923
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 A7030000000000 00i64 935
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 09000000000000 00i64 9
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 0C000000000000 00i64 12
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 E0330000000000 00i64 13280
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 775A0000000000 00i64 23159
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 B8370000000000 00i64 14264
1500F 0A 43010000 4701 0000map leaf, size 10: @143 → @147
15A4C 77616C6Ctxt "wall"
15F02 5E5E0000000000 00i64 24158
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 0A030000000000 00i64 778
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 65010000000000 00i64 357
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 C7220000000000 00i64 8903
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

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
rust274 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let options = RunOptions { page_size: 2, max_cost: std::time::Duration::from_secs(1), ..Default::default() };
let _rows = query.run(None, &options, None)?;
let result = 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

Query::close

rust18 B
pub fn close(self)

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
selfSelfConsumed 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
rust206 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut rows = query.run(None, &RunOptions::default(), None)?;
let result = rows.next_page()?;
query.close();
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

Rows::next_page

rust47 B
pub fn next_page(&mut self) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&mut SelfBorrowed for the callRequiredThe rows owner for this operation. Keep it alive during the call.

Errors

StatusWhen
Status::EVALUATION_FAILEDthe page does not render
Status::CLOSEDthe rows is closed
Status::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
rust191 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut rows = query.run(None, &RunOptions::default(), None)?;
let result = rows.next_page()?;
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

Rows::pages

rust36 B
pub fn pages(&mut self) -> Pages<'_>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&mut SelfBorrowed for the callRequiredThe rows owner for this operation. Keep it alive during the call.

Errors

StatusWhen
Status::EVALUATION_FAILEDa page does not render
Status::CLOSEDthe rows is closed
Status::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
rust515 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let options = RunOptions {
    page_size: 1,
    ..RunOptions::default()
};
let mut rows = query.run(None, &options, None)?;
let mut result = 0i64;
let mut pages = rows.pages();
while let Some(page) = pages.next() {
    let page = page?;
    let mut children = page.children(page.root()?);
    while let Some(child) = children.next() {
        child?;
        result += 1;
    }
    drop(children);
    page.close();
}
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

Rows::all_pages

rust47 B
pub fn all_pages(&mut self) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&mut SelfBorrowed for the callRequiredThe rows owner for this operation. Keep it alive during the call.

Errors

StatusWhen
Status::EVALUATION_FAILEDa page does not render
Status::CLOSEDthe rows is closed
Status::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
rust253 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let options = RunOptions {
    page_size: 1,
    ..RunOptions::default()
};
let mut rows = query.run(None, &options, None)?;
let result = rows.all_pages()?;
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

Rows::close

rust18 B
pub fn close(self)

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
selfSelfConsumed 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
rust205 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut rows = query.run(None, &RunOptions::default(), None)?;
let result = rows.next_page()?;
rows.close();
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

Query::subscribe

rust131 B
pub fn subscribe(
        &self,
        parameters: Option<&Document>,
        options: &RunOptions,
    ) -> Result<Subscription>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe query owner for this operation. Keep it alive during the call.
parametersOption<&Document>Borrowed 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.
options&RunOptionsValueRequired options record. See field defaultsThe operation's options record. See its field defaults.

Errors

StatusWhen
Status::INVALID_DEFINITIONthe query or its callable definitions are invalid
Status::INVALID_ARGUMENTthe parameters or subscription options are invalid
Status::CLOSEDthe query is closed
Status::OUT_OF_MEMORYnative memory is exhausted
Status::LOCKEDthe shared wake dispatcher has no signal admission slot

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
rust261 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut subscription = query.subscribe(None, &RunOptions::default())?;
let event = subscription.next().await?.ok_or("no initial event")?;
let result = event.result;
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
rust254 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut subscription = query.subscribe(None, &RunOptions::default())?;
let event = subscription.next().await?.ok_or("no initial event")?;
let result = event;
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

Subscription::next

rust53 B
pub async fn next(&mut self) -> Result<Option<Event>>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&mut SelfBorrowed for the callRequiredThe subscription owner for this operation. Keep it alive during the call.

Errors

StatusWhen
Status::EVALUATION_FAILEDa rerun of the query failed. Every later call reports this failure
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

Await one owned event with any executor. Cancellation and closure return None. A failed rerun reports its native diagnostic. Dropping a pending future loses no event. Obtain a Canceller before borrowing the subscription for a wait. Use the executor's timeout or cancellation facilities to bound the wait.

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
rust261 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut subscription = query.subscribe(None, &RunOptions::default())?;
let event = subscription.next().await?.ok_or("no initial event")?;
let result = event.result;
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

Subscription::events

rust38 B
pub fn events(&mut self) -> Events<'_>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&mut SelfBorrowed for the callRequiredThe subscription owner for this operation. Keep it alive during the call.

Errors

Cancellation and closure end iteration. The iteration reports other terminal failures.

StatusWhen
Status::EVALUATION_FAILEDa rerun of the query failed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

Call events.next().await until None. Each event owns its result document. Cancellation and closure end the sequence. A query failure is returned once. Dropping the sequence early cancels the subscription. Drop or close the subscription to release its owner.

Examples

subscription/events

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
rust270 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut subscription = query.subscribe(None, &RunOptions::default())?;
let event = subscription.events().next().await.ok_or("no initial event")??;
let result = event.result;
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

Subscription::cancel

rust20 B
pub fn cancel(&self)

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed 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
rust323 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut subscription = query.subscribe(None, &RunOptions::default())?;
let canceller = subscription.canceller();
let event = subscription.next().await?.ok_or("no initial event")?;
canceller.cancel();
let result = event.result;
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

Subscription::close

rust19 B
pub fn close(&self)

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfConsumed 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
rust283 B
let definition = stardust::parse(query_text, Format::TRON)?;
let query = db.query(&definition)?;
let mut subscription = query.subscribe(None, &RunOptions::default())?;
let event = subscription.next().await?.ok_or("no initial event")?;
let result = event.result;
subscription.close();
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

Mutation::run

rust166 B
pub fn run(
        &self,
        parameters: Option<&Document>,
        options: &RunOptions,
        explain: Option<&mut MutationExplain>,
    ) -> Result<Commit>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe mutation owner for this operation. Keep it alive during the call.
parametersOption<&Document>Borrowed 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.
options&RunOptionsValueRequired options record. See field defaultsThe operation's options record. See its field defaults.
explainOption<&mut MutationExplain>Caller-owned outputAbsent skips explain outputOptional explain output. This record contains explain output for mutation run.

Errors

StatusWhen
Status::INVALID_DEFINITIONthe mutation selection or definition is invalid
Status::INVALID_ARGUMENTthe parameters or run options are invalid
Status::SCHEMA_VIOLATIONthe write breaks a schema
Status::CONFLICTconcurrent writes prevent the commit
Status::REJECTEDa mutation target or write guard refuses the write
Status::UNAVAILABLEthe patch sets stardust/history and no enabled plugin purges history
Status::EVALUATION_FAILEDthe mutation fails
Status::CLOSEDthe mutation is closed
Status::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
rust161 B
let source = stardust::parse(birthday_text, Format::TRON)?;
let mutation = db.mutation(&source)?;
let result = mutation.run(None, &RunOptions::default(), None)?;
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 15426D3C35AD3F 00i64 17923367691436565
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
rust240 B
let source = stardust::parse(birthday_text, Format::TRON)?;
let mutation = db.mutation(&source)?;
let mut explain = stardust::MutationExplain::default();
mutation.run(None, &RunOptions::default(), Some(&mut explain))?;
let result = explain;
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 81060000000000 00i64 1665
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 87060000000000 00i64 1671
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 0B000000000000 00i64 11
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 0D000000000000 00i64 13
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 16270000000000 00i64 10006
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 C7A00000000000 00i64 41159
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 102E0000000000 00i64 11792
1500F 0A 43010000 4701 0000map leaf, size 10: @143 → @147
15A4C 77616C6Ctxt "wall"
15F02 CEA70000000000 00i64 42958
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

Mutation::close

rust18 B
pub fn close(self)

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
selfSelfConsumed 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
rust179 B
let source = stardust::parse(birthday_text, Format::TRON)?;
let mutation = db.mutation(&source)?;
let result = mutation.run(None, &RunOptions::default(), None)?;
mutation.close();
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 FCC1603C35AD3F 00i64 17923367690617340
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

Database::merge_patch

rust128 B
pub fn merge_patch(
        &self,
        patch: &Document,
        explain: Option<&mut PatchExplain>,
    ) -> Result<Commit>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
patch&DocumentBorrowed 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.
explainOption<&mut PatchExplain>Caller-owned outputAbsent skips explain outputOptional explain output. This record contains explain output for merge_patch.

Errors

StatusWhen
Status::INVALID_COMMIT_TIMEthe #_tx commit time is not later than the last commit
Status::CONFLICTan entity revision check fails or a concurrent writer prevents the commit; a revision mismatch reports the entity and expected and actual revisions
Status::REJECTEDthe database refuses the patch; the code and diagnostic path name the reason and key
Status::UNAVAILABLEthe patch sets stardust/history and no enabled plugin purges history
Status::INVALID_ARGUMENTthe patch is not an entity-keyed object, or a link names an ID outside the user entity range
Status::CLOSEDthe database is closed
Status::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
rust98 B
let patch = stardust::parse(seed_text, Format::TRON)?;
let result = db.merge_patch(&patch, None)?;
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 39840D3C35AD3F 00i64 17923367685162041
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
rust174 B
let patch = stardust::parse(seed_text, Format::TRON)?;
let mut explain = stardust::PatchExplain::default();
db.merge_patch(&patch, Some(&mut explain))?;
let result = explain;
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 30070000000000 00i64 1840
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 770C0000000000 00i64 3191
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 F2010000000000 00i64 498
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 328F0000000000 00i64 36658
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 8F090000000000 00i64 2447
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 1B9C0000000000 00i64 39963
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
rust104 B
let patch = stardust::parse(patch_text, Format::TRON)?;
let result = db.merge_patch(&patch, None).err();
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
rust194 B
let future = stardust::parse(future_text, Format::TRON)?;
db.merge_patch(&future, None)?;
let older = stardust::parse(older_text, Format::TRON)?;
let result = db.merge_patch(&older, None).err();
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

Database::indexes_sync

rust60 B
pub fn indexes_sync(&self, max_wait: Duration) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
max_waitDurationValueRequiredThe maximum wait. Zero checks once.

Errors

std::time::Duration cannot represent a negative max_wait. The safe host API cannot represent this argument. It makes no native call.

StatusWhen
Status::TIMEOUTmax_wait passed first
Status::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

rust106 B
db.indexes_sync(std::time::Duration::from_secs(5))?;
let result = db.definitions("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

Database::bulk_begin

rust38 B
pub fn bulk_begin(&self) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.

Errors

StatusWhen
Status::INVALID_ARGUMENTa bulk build is already in progress on the database
Status::CLOSEDthe database is closed
Status::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

rust34 B
db.bulk_begin()?;
db.bulk_abort();

C exports: stardust_db_bulk_begin

Database::bulk_add

rust54 B
pub fn bulk_add(&self, patch: &Document) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.
patch&DocumentBorrowed 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
Status::INVALID_ARGUMENTno bulk build is in progress
Status::REJECTEDthe database refuses the patch; the build has failed and later adds report the same status
Status::CLOSEDthe database is closed
Status::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

rust360 B
db.bulk_begin()?;
// The first entity of an empty database is 1, so the second patch updates it.
// A failed add leaves the build for finish or abort; close also drops it.
db.bulk_add(&stardust::parse(r##"{"#_ada":{"name":"Ada"}}"##, Format::JSON)?)?;
db.bulk_add(&stardust::parse(r##"{"1":{"title":"Countess"}}"##, Format::JSON)?)?;
db.bulk_finish()?.close();

C exports: stardust_db_bulk_add

Database::bulk_finish

rust45 B
pub fn bulk_finish(&self) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe database owner for this operation. Keep it alive during the call.

Errors

StatusWhen
Status::INVALID_ARGUMENTno bulk build is in progress
Status::REJECTEDthe database refuses a patch; an initial build publishes nothing and fallback keeps earlier commits
Status::CONFLICTanother write committed to the database during the build
Status::CLOSEDthe database is closed
Status::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

rust298 B
db.bulk_begin()?;
db.bulk_add(&stardust::parse(r##"{"#_ada":{"name":"Ada","title":"Countess"}}"##, Format::JSON)?)?;
// Finish ends the build also when it fails. The summary holds status,
// patches, transactions, facts, entities and phase timings.
let summary = db.bulk_finish()?;
summary.close();

C exports: stardust_db_bulk_finish, stardust_result_take_document, stardust_result_error, stardust_result_release

Database::bulk_abort

rust24 B
pub fn bulk_abort(&self)

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed 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

rust210 B
let patch = stardust::parse(r##"{"#_ada":{"name":"Ada"}}"##, Format::JSON)?;
db.bulk_begin()?;
let added = db.bulk_add(&patch);
// Abort writes nothing; without a build it does nothing.
db.bulk_abort();
added?;

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_sizeu32CountHost 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_ofi64NoneHost 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
statusCommitStatusNoneHost type range——
transactioni64NoneHost type range—Zero when nothing was written.
factsi64CountHost type range——
committed_atOption<SystemTime>UTC instant (100 ns ticks since the Unix epoch at the ABI)Tick rangeNoneRecorded commit time as a UTC instant. The call measures this value. Independent calls can differ.
idsHashMap<String, i64>NoneHost 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
sequencei64CountEvent number. Event 1 is the initial result.
supersededi64CountIntermediate 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.
transactioni64NoneTransaction the result was computed at.
resultDocumentNoneThe full query result. The event owns it and the consumer closes it.