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
c1.5 kB
stardust_document *birthday = NULL;
stardust_document *definition = NULL;
stardust_db_mutation *mutation = NULL;
stardust_result *committed = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_result *page = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(birthday_text, STARDUST_TRON, &birthday);
if (status == STARDUST_OK) status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source change = {.kind = STARDUST_SOURCE_DOCUMENT, .document = birthday};
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_mutation_open(db, &change, &mutation);
if (status == STARDUST_OK) status = stardust_db_mutation_run(mutation, NULL, NULL, NULL, &committed);
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, NULL, NULL, &rows);
if (status == STARDUST_OK) status = stardust_db_rows_next(rows, &page);
if (status == STARDUST_OK) status = stardust_result_take_document(page, &result);
stardust_result_release(page);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_result_release(committed);
stardust_db_mutation_release(mutation);
stardust_document_release(definition);
stardust_document_release(birthday);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
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
stardust_db_read_entityStatus. document through outputdatabase.read_entity(entity, max_depth, max_entities) atomically returns an owned {document links revisions truncated} document, expanding links up to max_depth hops.
stardust_db_query_openStatus. query through outputOpen an owned query from a path or an inline definition.
stardust_db_mutation_openStatus. mutation through outputOpen an owned mutation from a path or an inline definition.
stardust_db_query_runStatus. rows through outputRun the query and return an owned row cursor.
stardust_db_query_releasevoidRelease the query handle.
stardust_db_rows_nextStatus. document through outputRead the next page as an owned document.
pagesUnavailablerows.pages() iterates the non-empty pages of the cursor.
all_pagesUnavailablerows.all_pages() reads every remaining page into one owned array document.
stardust_db_rows_releasevoidRelease the rows handle.
stardust_db_query_subscribeStatus. subscription through outputquery.subscribe(parameters, options) opens an owned live subscription.
stardust_db_subscription_nextStatus. event through outputWait for the next live event.
eventsUnavailablesubscription.events() delivers events in order until the subscription is cancelled, closes or fails.
stardust_db_subscription_cancelvoidsubscription.cancel() ends the subscription.
stardust_db_subscription_releasevoidRelease the subscription handle.
stardust_db_mutation_runStatus. commit through outputRun the mutation and return commit information.
stardust_db_mutation_releasevoidRelease the mutation handle.
stardust_db_merge_patchStatus. commit through outputdatabase.merge_patch(patch) applies an entity-keyed patch document in one transaction and returns commit information.
stardust_db_indexes_syncStatus. none through outputdatabase.indexes_sync(max_wait) waits until the database built every exact index that earlier definition commits and inline runs ask for.
stardust_db_bulk_beginStatus. none through outputdatabase.bulk_begin() starts a bulk build of data merge patches held by the database.
stardust_db_bulk_addStatus. none through outputdatabase.bulk_add(patch) copies and queues one merge-patch document in the bulk build.
stardust_db_bulk_finishStatus. document through outputdatabase.bulk_finish() publishes the bulk build with one commit, ends it and returns an owned summary document.
stardust_db_bulk_abortvoiddatabase.bulk_abort() drops the bulk build in progress without writing it.
stardust_db_subscription_set_notifystatusWake a host scheduler when a subscription may be ready.

stardust_db_read_entity

c133 B
uint32_t stardust_db_read_entity(stardust_db *db, int64_t entity, int64_t max_depth, int64_t max_entities, stardust_result **output);
c92 B
uint32_t stardust_result_take_document(stardust_result *result, stardust_document **output);
c96 B
uint32_t stardust_result_error(const stardust_result *result, stardust_diagnostic_view *output);
c54 B
void stardust_result_release(stardust_result *result);

Parameters

stardust_db_read_entity

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.
entityint64_tValueRequiredThe decimal user entity ID.
max_depthint64_tValueRequiredLink hops to expand along each path, 0 through 32. 0, the default, leaves every link a {#link id} reference.
max_entitiesint64_tValueRequiredThe 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.
outputstardust_result **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_take_document

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_error

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_release

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTthe entity ID is outside the user entity range, max_depth is negative or above 32, or max_entities is negative
STARDUST_CLOSEDthe database is closed
STARDUST_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

c330 B
stardust_document *result = NULL;
stardust_result *outcome = NULL;
uint32_t status = stardust_db_read_entity(db, 2, 1, 0, &outcome);
if (status == STARDUST_OK) status = stardust_result_take_document(outcome, &result);
stardust_result_release(outcome);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
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

Also calls: stardust_result_take_document, stardust_result_error, stardust_result_release

stardust_db_query_open

c111 B
uint32_t stardust_db_query_open(stardust_db *db, const stardust_db_source *source, stardust_db_query **output);
c100 B
uint32_t stardust_db_query_error(const stardust_db_query *handle, stardust_diagnostic_view *output);

Parameters

stardust_db_query_open

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.
sourceconst stardust_db_source *Borrowed inputRequiredAn inline native definition or a stored definition path.
outputstardust_db_query **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_db_query_error

ParameterTypeOwnershipDefaultMeaning
handleconst stardust_db_query *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_NOT_FOUNDno definition is stored at the path
STARDUST_INVALID_DEFINITIONthe definition is invalid
STARDUST_CLOSEDthe database is closed
STARDUST_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

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
c868 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_result *page = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, NULL, NULL, &rows);
if (status == STARDUST_OK) status = stardust_db_rows_next(rows, &page);
if (status == STARDUST_OK) status = stardust_result_take_document(page, &result);
stardust_result_release(page);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

Refuse an invalid query definition

definition_text holds this document:

TRON43 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
042C 3F78txt "?x"
070E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
144C 66696E64txt "find"
190F 0A 14000000 0700 0000map leaf, size 10: @14 → @7
c496 B
stardust_document *definition = NULL;
uint32_t status = stardust_parse(definition_text, STARDUST_TRON, &definition);
if (status != STARDUST_OK) {stardust_document_release(definition); return status;}
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
stardust_db_query *failed = NULL;
status = stardust_db_query_open(db, &source, &failed);
stardust_document_release(definition);
stardust_diagnostic_view result = {0};
stardust_db_query_error(failed, &result);
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

c287 B
stardust_db_source source = {.kind = STARDUST_SOURCE_PATH, .path = {(const uint8_t *)"people/missing", 14}};
stardust_db_query *failed = NULL;
uint32_t status = stardust_db_query_open(db, &source, &failed);
stardust_diagnostic_view result = {0};
stardust_db_query_error(failed, &result);
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

Also calls: stardust_db_query_error

stardust_db_mutation_open

c117 B
uint32_t stardust_db_mutation_open(stardust_db *db, const stardust_db_source *source, stardust_db_mutation **output);
c106 B
uint32_t stardust_db_mutation_error(const stardust_db_mutation *handle, stardust_diagnostic_view *output);

Parameters

stardust_db_mutation_open

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.
sourceconst stardust_db_source *Borrowed inputRequiredAn inline native definition or a stored definition path.
outputstardust_db_mutation **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_db_mutation_error

ParameterTypeOwnershipDefaultMeaning
handleconst stardust_db_mutation *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_NOT_FOUNDno definition is stored at the path
STARDUST_INVALID_DEFINITIONthe definition is invalid
STARDUST_CLOSEDthe database is closed
STARDUST_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

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
c615 B
stardust_document *definition = NULL;
stardust_db_mutation *mutation = NULL;
stardust_result *result = NULL;
uint32_t status = stardust_parse(birthday_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_mutation_open(db, &source, &mutation);
if (status == STARDUST_OK) status = stardust_db_mutation_run(mutation, NULL, NULL, NULL, &result);
stardust_db_mutation_release(mutation);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_result_release(result); return status;}
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 3F9FB74A35AD3F 00i64 17923367931191103
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

Also calls: stardust_db_mutation_error

stardust_db_query_run

c206 B
uint32_t stardust_db_query_run(stardust_db_query *query_handle, const stardust_document *parameters, const stardust_db_query_options *options, stardust_db_query_explain *explain, stardust_db_rows **output);
c96 B
uint32_t stardust_db_rows_error(const stardust_db_rows *rows, stardust_diagnostic_view *output);

Parameters

stardust_db_query_run

ParameterTypeOwnershipDefaultMeaning
query_handlestardust_db_query *Borrowed handleRequiredKeep the handle alive until the call returns.
parametersconst stardust_document *Borrowed handleNULLAn 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.
optionsconst stardust_db_query_options *Borrowed inputNULLThe operation's options record. See its field defaults.
explainstardust_db_query_explain *Caller-owned outputNULLReceives a record. Its pointer fields follow the record's ownership contract.
outputstardust_db_rows **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_db_rows_error

ParameterTypeOwnershipDefaultMeaning
rowsconst stardust_db_rows *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_NOT_FOUNDthe stored query definition was deleted
STARDUST_INVALID_DEFINITIONthe loaded query definition is invalid
STARDUST_INVALID_ARGUMENTthe parameters or run options are invalid
STARDUST_EVALUATION_FAILEDthe query fails or exceeds max_cost
STARDUST_CLOSEDthe parent database is closed
STARDUST_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
c868 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_result *page = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, NULL, NULL, &rows);
if (status == STARDUST_OK) status = stardust_db_rows_next(rows, &page);
if (status == STARDUST_OK) status = stardust_result_take_document(page, &result);
stardust_result_release(page);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
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
c1.1 kB
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_document *boundary = NULL;
uint32_t boundary_root = 0;
int64_t ticks = 0;
uint32_t status = stardust_parse(boundary_text, STARDUST_TRON, &boundary);
if (status == STARDUST_OK) status = stardust_document_root(boundary, &boundary_root);
if (status == STARDUST_OK) status = stardust_document_i64(boundary, boundary_root, &ticks);
stardust_document_release(boundary);
if (status == STARDUST_OK) status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
stardust_db_query_options result = {.size=sizeof(result), .version=1, .page_size=2, .max_cost_ticks=ticks};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, &result, NULL, &rows);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) return status;
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

The C ABI takes complete 100-ns ticks

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
c532 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
stardust_db_query_options result = {.size=sizeof(result), .version=1, .page_size=2, .max_cost_ticks=1};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) return status;
TRON112 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
048C 6D61785F636F73 74txt "max_cost"
0D02 01000000000000 00i64 1
160F 0A 04000000 0D00 0000map leaf, size 10: @4 → @D
205C 61735F6F66txt "as_of"
2602 00000000000000 00i64 0
2F0F 0A 20000000 2600 0000map leaf, size 10: @20 → @26
399C 706167655F7369 7A65txt "page_size"
4302 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
c671 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_db_query_explain explain = {0};
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, NULL, &explain, &rows);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) return status;
stardust_db_query_explain 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 AB020000000000 00i64 683
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 B8020000000000 00i64 696
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 08000000000000 00i64 8
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 0A000000000000 00i64 10
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 8D1F0000000000 00i64 8077
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 D81F0000000000 00i64 8152
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 5B220000000000 00i64 8795
1500F 0A 43010000 4701 0000map leaf, size 10: @143 → @147
15A4C 77616C6Ctxt "wall"
15F02 B4220000000000 00i64 8884
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 B3010000000000 00i64 435
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 FE000000000000 00i64 254
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 32140000000000 00i64 5170
30B0F 0A FD020000 0203 0000map leaf, size 10: @2FD → @302
31507 0E 88000000 F302 0000 0B030000map branch, size 14, depth 1, slots 3, 7: @2F3 → @30B
323FC 6D656D6F72795F 7265667573616C73txt "memory_refusals"
33302 00000000000000 00i64 0
33C0F 0A 23030000 3303 0000map leaf, size 10: @323 → @333
346CC 6275646765745F 6279746573txt "budget_bytes"
35302 00823E71020000 00i64 10489856512
35C0F 0A 46030000 5303 0000map leaf, size 10: @346 → @353
3665C 746F74616Ctxt "total"
36C0F 0A 66030000 7201 0000map leaf, size 10: @366 → @172
37614 11 627564676574 5F7065616B5F6279 746573txt "budget_peak_bytes"
38902 BB370000000000 00i64 14267
3920F 0A 76030000 8903 0000map leaf, size 10: @376 → @389
39C07 16 13040000 3C03 0000 5C030000 6C03 0000 92030000map branch, size 22, depth 1, slots 0, 1, 4, 10: @33C → @35C → @36C → @392
3B25C 7265747279txt "retry"
3B802 00000000000000 00i64 0
3C10F 0A B2030000 B803 0000map leaf, size 10: @3B2 → @3B8
3CB7C 72657472696573txt "retries"
3D302 00000000000000 00i64 0
3DC0F 0A CB030000 D303 0000map leaf, size 10: @3CB → @3D3
3E6CC 6D656D6F72795F 6279746573txt "memory_bytes"
3F302 6B170000000000 00i64 5995
3FC0F 0A E6030000 F303 0000map leaf, size 10: @3E6 → @3F3
406FC 6C6F61645F6465 66696E6974696F6Etxt "load_definition"
4160F 0A 06040000 5200 0000map leaf, size 10: @406 → @52
42007 0E 01100000 FC03 0000 16040000map branch, size 14, depth 1, slots 0, 12: @3FC → @416
42E07 36 FBDA0000 9501 0000 DD010000 FE01 0000 19020000 2E02 0000 76020000 CC02 0000 15030000 9C03 0000 C1030000 DC03 0000 20040000map branch, size 54, depth 0 (root), slots 0, 1, 3, 4, 5, 6, 7, 9, 11, 12, 14, 15: @195 → @1DD → @1FE → @219 → @22E → @276 → @2CC → @315 → @39C → @3C1 → @3DC → @420
Offset (hex)Bytes (hex)Meaning

A negative configured duration is not an absent field

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

Run with typed query options

query_text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
c713 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
stardust_db_query_options result = {.size=sizeof(result), .version=1, .page_size=2, .max_cost_ticks=STARDUST_TICKS_PER_SECOND};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, &result, NULL, &rows);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) return status;
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

Also calls: stardust_db_rows_error

stardust_db_query_release

c64 B
void stardust_db_query_release(stardust_db_query *query_handle);

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
query_handlestardust_db_query *Consumed handleNULLEnds ownership. Do not use the handle 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
c868 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_result *page = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, NULL, NULL, &rows);
if (status == STARDUST_OK) status = stardust_db_rows_next(rows, &page);
if (status == STARDUST_OK) status = stardust_result_take_document(page, &result);
stardust_result_release(page);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
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

stardust_db_rows_next

c79 B
uint32_t stardust_db_rows_next(stardust_db_rows *rows, stardust_result **page);
c92 B
uint32_t stardust_result_take_document(stardust_result *result, stardust_document **output);
c96 B
uint32_t stardust_result_error(const stardust_result *result, stardust_diagnostic_view *output);
c54 B
void stardust_result_release(stardust_result *result);

Parameters

stardust_db_rows_next

ParameterTypeOwnershipDefaultMeaning
rowsstardust_db_rows *Borrowed handleRequiredKeep the handle alive until the call returns.
pagestardust_result **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_take_document

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_error

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_release

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_EVALUATION_FAILEDthe page does not render
STARDUST_CLOSEDthe parent database is closed
STARDUST_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

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
c868 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_result *page = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, NULL, NULL, &rows);
if (status == STARDUST_OK) status = stardust_db_rows_next(rows, &page);
if (status == STARDUST_OK) status = stardust_result_take_document(page, &result);
stardust_result_release(page);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
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

Also calls: stardust_result_take_document, stardust_result_error, stardust_result_release

pages

Call stardust_db_rows_next until a page root has no first child.

Also calls: stardust_db_rows_next, stardust_result_take_document, stardust_result_error, stardust_result_release, stardust_document_root, stardust_document_read_many, stardust_document_release

all_pages

Copy each page's rows into one stardust_document_builder_add_many array.

Also calls: 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

stardust_db_rows_release

c54 B
void stardust_db_rows_release(stardust_db_rows *rows);

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
rowsstardust_db_rows *Consumed handleNULLEnds ownership. Do not use the handle 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
c868 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_result *page = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_run(query, NULL, NULL, NULL, &rows);
if (status == STARDUST_OK) status = stardust_db_rows_next(rows, &page);
if (status == STARDUST_OK) status = stardust_result_take_document(page, &result);
stardust_result_release(page);
stardust_db_rows_release(rows);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
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

stardust_db_query_subscribe

c184 B
uint32_t stardust_db_query_subscribe(stardust_db_query *query_handle, const stardust_document *parameters, const stardust_db_query_options *options, stardust_db_subscription **output);
c111 B
uint32_t stardust_db_subscription_error(const stardust_db_subscription *sub, stardust_diagnostic_view *output);

Parameters

stardust_db_query_subscribe

ParameterTypeOwnershipDefaultMeaning
query_handlestardust_db_query *Borrowed handleRequiredKeep the handle alive until the call returns.
parametersconst stardust_document *Borrowed handleNULLAn 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.
optionsconst stardust_db_query_options *Borrowed inputNULLThe operation's options record. See its field defaults.
outputstardust_db_subscription **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_db_subscription_error

ParameterTypeOwnershipDefaultMeaning
subconst stardust_db_subscription *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

Errors

StatusWhen
STARDUST_INVALID_DEFINITIONthe query or its callable definitions are invalid
STARDUST_INVALID_ARGUMENTthe parameters or subscription options are invalid
STARDUST_CLOSEDthe parent database is closed
STARDUST_OUT_OF_MEMORYnative memory is exhausted

Notes

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

Blocking next works without registration. To wake your scheduler, see Readiness callbacks for registration, waiting and context lifetime.

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
c835 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_subscription *subscription = NULL;
stardust_db_live_event event = {0};
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_subscribe(query, NULL, NULL, &subscription);
if (status == STARDUST_OK) status = stardust_db_subscription_next(subscription, 0, &event);
stardust_db_subscription_release(subscription);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(event.result); return status;}
stardust_document *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
c832 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_subscription *subscription = NULL;
stardust_db_live_event event = {0};
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_subscribe(query, NULL, NULL, &subscription);
if (status == STARDUST_OK) status = stardust_db_subscription_next(subscription, 0, &event);
stardust_db_subscription_release(subscription);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(event.result); return status;}
stardust_db_live_event 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

Also calls: stardust_db_subscription_error

stardust_db_subscription_next

c125 B
uint32_t stardust_db_subscription_next(stardust_db_subscription *sub, int64_t max_wait_ticks, stardust_db_live_event *event);
c111 B
uint32_t stardust_db_subscription_error(const stardust_db_subscription *sub, stardust_diagnostic_view *output);
c55 B
void stardust_document_release(stardust_document *doc);

Parameters

stardust_db_subscription_next

ParameterTypeOwnershipDefaultMeaning
substardust_db_subscription *Borrowed handleRequiredKeep the handle alive until the call returns.
max_wait_ticksint64_tValueRequiredValue passed to the call.
eventstardust_db_live_event *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_db_subscription_error

ParameterTypeOwnershipDefaultMeaning
subconst stardust_db_subscription *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_document_release

ParameterTypeOwnershipDefaultMeaning
docstardust_document *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTmax_wait is negative
STARDUST_CANCELLEDthe subscription is cancelled or closed
STARDUST_EVALUATION_FAILEDa rerun of the query failed. Every later call reports this failure
STARDUST_CLOSEDthe parent database is closed
STARDUST_OUT_OF_MEMORYnative memory is exhausted

Notes

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

Examples

subscription/next

query_text holds this document:

TRON165 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
172C 3F65txt "?e"
1A4C 6E616D65txt "name"
1F5C 3F6E616D65txt "?name"
250E 15 00 0700 030000 00 17000000 1A0000 00 1F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1A → @1F
3A0E 0D 00 0100 010000 00 25000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @25
475C 3F6E616D65txt "?name"
4D0E 0D 00 0100 010000 00 47000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @47
5A5C 7768657265txt "where"
600F 0A 5A000000 3A00 0000map leaf, size 10: @5A → @3A
6A4C 66696E64txt "find"
6F0F 0A 6A000000 0A00 0000map leaf, size 10: @6A → @A
797C 6F726465724279txt "orderBy"
810F 0A 79000000 4D00 0000map leaf, size 10: @79 → @4D
8B07 12 2A000000 6000 0000 6F000000 8100 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @60 → @6F → @81
c835 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_subscription *subscription = NULL;
stardust_db_live_event event = {0};
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_subscribe(query, NULL, NULL, &subscription);
if (status == STARDUST_OK) status = stardust_db_subscription_next(subscription, 0, &event);
stardust_db_subscription_release(subscription);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(event.result); return status;}
stardust_document *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

Also calls: stardust_db_subscription_error, stardust_document_release

events

Call stardust_db_subscription_next repeatedly.

Also calls: stardust_db_subscription_next, stardust_db_subscription_error

stardust_db_subscription_cancel

c68 B
void stardust_db_subscription_cancel(stardust_db_subscription *sub);

Parameters

ParameterTypeOwnershipDefaultMeaning
substardust_db_subscription *Borrowed handleNULLKeep the handle alive until the call returns.

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
c882 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_subscription *subscription = NULL;
stardust_db_live_event event = {0};
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_subscribe(query, NULL, NULL, &subscription);
if (status == STARDUST_OK) status = stardust_db_subscription_next(subscription, 0, &event);
stardust_db_subscription_cancel(subscription);
stardust_db_subscription_release(subscription);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(event.result); return status;}
stardust_document *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

stardust_db_subscription_release

c69 B
void stardust_db_subscription_release(stardust_db_subscription *sub);

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
substardust_db_subscription *Consumed handleNULLEnds ownership. Do not use the handle 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
c835 B
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_subscription *subscription = NULL;
stardust_db_live_event event = {0};
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_subscribe(query, NULL, NULL, &subscription);
if (status == STARDUST_OK) status = stardust_db_subscription_next(subscription, 0, &event);
stardust_db_subscription_release(subscription);
stardust_db_query_release(query);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_document_release(event.result); return status;}
stardust_document *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

stardust_db_mutation_run

c210 B
uint32_t stardust_db_mutation_run(stardust_db_mutation *mutation, const stardust_document *parameters, const stardust_db_write_options *options, stardust_db_mutation_explain *explain, stardust_result **output);
c102 B
uint32_t stardust_db_result_commit_info(const stardust_result *result, stardust_db_commit_info *info);
c96 B
uint32_t stardust_result_error(const stardust_result *result, stardust_diagnostic_view *output);
c54 B
void stardust_result_release(stardust_result *result);

Parameters

stardust_db_mutation_run

ParameterTypeOwnershipDefaultMeaning
mutationstardust_db_mutation *Borrowed handleRequiredKeep the handle alive until the call returns.
parametersconst stardust_document *Borrowed handleNULLAn 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.
optionsconst stardust_db_write_options *Borrowed inputNULLThe operation's options record. See its field defaults.
explainstardust_db_mutation_explain *Caller-owned outputNULLReceives a record. Its pointer fields follow the record's ownership contract.
outputstardust_result **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_db_result_commit_info

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
infostardust_db_commit_info *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_error

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_release

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_DEFINITIONthe mutation selection or definition is invalid
STARDUST_INVALID_ARGUMENTthe parameters or run options are invalid
STARDUST_SCHEMA_VIOLATIONthe write breaks a schema
STARDUST_CONFLICTconcurrent writes prevent the commit
STARDUST_REJECTEDa mutation target or write guard refuses the write
STARDUST_UNAVAILABLEthe patch sets stardust/history and no enabled plugin purges history
STARDUST_EVALUATION_FAILEDthe mutation fails
STARDUST_CLOSEDthe parent database is closed
STARDUST_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
c615 B
stardust_document *definition = NULL;
stardust_db_mutation *mutation = NULL;
stardust_result *result = NULL;
uint32_t status = stardust_parse(birthday_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_mutation_open(db, &source, &mutation);
if (status == STARDUST_OK) status = stardust_db_mutation_run(mutation, NULL, NULL, NULL, &result);
stardust_db_mutation_release(mutation);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_result_release(result); return status;}
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 3D9BFF4A35AD3F 00i64 17923367935908669
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
c711 B
stardust_document *definition = NULL;
stardust_db_mutation *mutation = NULL;
stardust_result *written = NULL;
stardust_db_mutation_explain explain = {0};
uint32_t status = stardust_parse(birthday_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_mutation_open(db, &source, &mutation);
if (status == STARDUST_OK) status = stardust_db_mutation_run(mutation, NULL, NULL, &explain, &written);
stardust_result_release(written);
stardust_db_mutation_release(mutation);
stardust_document_release(definition);
if (status != STARDUST_OK) return status;
stardust_db_mutation_explain 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 C7030000000000 00i64 967
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 CE030000000000 00i64 974
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 08000000000000 00i64 8
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 0A000000000000 00i64 10
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 671B0000000000 00i64 7015
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 71850000000000 00i64 34161
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 9B1F0000000000 00i64 8091
1500F 0A 43010000 4701 0000map leaf, size 10: @143 → @147
15A4C 77616C6Ctxt "wall"
15F02 B6890000000000 00i64 35254
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

Also calls: stardust_db_result_commit_info, stardust_result_error, stardust_result_release

stardust_db_mutation_release

c66 B
void stardust_db_mutation_release(stardust_db_mutation *mutation);

Consumes the receiver handle.

Parameters

ParameterTypeOwnershipDefaultMeaning
mutationstardust_db_mutation *Consumed handleNULLEnds ownership. Do not use the handle 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
c615 B
stardust_document *definition = NULL;
stardust_db_mutation *mutation = NULL;
stardust_result *result = NULL;
uint32_t status = stardust_parse(birthday_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_mutation_open(db, &source, &mutation);
if (status == STARDUST_OK) status = stardust_db_mutation_run(mutation, NULL, NULL, NULL, &result);
stardust_db_mutation_release(mutation);
stardust_document_release(definition);
if (status != STARDUST_OK) {stardust_result_release(result); return status;}
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 6E83F34A35AD3F 00i64 17923367935116142
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

stardust_db_merge_patch

c186 B
uint32_t stardust_db_merge_patch(stardust_db *db, const stardust_document *patch, const stardust_db_write_options *options, stardust_db_patch_explain *explain, stardust_result **output);
c102 B
uint32_t stardust_db_result_commit_info(const stardust_result *result, stardust_db_commit_info *info);
c96 B
uint32_t stardust_result_error(const stardust_result *result, stardust_diagnostic_view *output);
c54 B
void stardust_result_release(stardust_result *result);

Parameters

stardust_db_merge_patch

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.
patchconst stardust_document *Borrowed handleRequiredAn 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.
optionsconst stardust_db_write_options *Borrowed inputNULLCaller-owned record read during the call.
explainstardust_db_patch_explain *Caller-owned outputNULLReceives a record. Its pointer fields follow the record's ownership contract.
outputstardust_result **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_db_result_commit_info

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
infostardust_db_commit_info *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_error

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_release

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_COMMIT_TIMEthe #_tx commit time is not later than the last commit
STARDUST_CONFLICTan entity revision check fails or a concurrent writer prevents the commit; a revision mismatch reports the entity and expected and actual revisions
STARDUST_REJECTEDthe database refuses the patch; the code and diagnostic path name the reason and key
STARDUST_UNAVAILABLEthe patch sets stardust/history and no enabled plugin purges history
STARDUST_INVALID_ARGUMENTthe patch is not an entity-keyed object, or a link names an ID outside the user entity range
STARDUST_CLOSEDthe database is closed
STARDUST_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
c336 B
stardust_document *patch = NULL;
stardust_result *result = NULL;
uint32_t status = stardust_parse(seed_text, STARDUST_TRON, &patch);
if (status == STARDUST_OK) status = stardust_db_merge_patch(db, patch, NULL, NULL, &result);
stardust_document_release(patch);
if (status != STARDUST_OK) {stardust_result_release(result); return status;}
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 84AC8E4A35AD3F 00i64 17923367928507524
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
c426 B
stardust_document *patch = NULL;
stardust_db_patch_explain explain = {0};
stardust_result *written = NULL;
uint32_t status = stardust_parse(seed_text, STARDUST_TRON, &patch);
if (status == STARDUST_OK) status = stardust_db_merge_patch(db, patch, NULL, &explain, &written);
stardust_result_release(written);
stardust_document_release(patch);
if (status != STARDUST_OK) return status;
stardust_db_patch_explain 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 47050000000000 00i64 1351
0300F 0A 23000000 2700 0000map leaf, size 10: @23 → @27
03A4C 77616C6Ctxt "wall"
03F02 4A050000000000 00i64 1354
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 46010000000000 00i64 326
0900F 0A 83000000 8700 0000map leaf, size 10: @83 → @87
09A4C 77616C6Ctxt "wall"
09F02 01C60000000000 00i64 50689
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 F5060000000000 00i64 1781
0F00F 0A E3000000 E700 0000map leaf, size 10: @E3 → @E7
0FA4C 77616C6Ctxt "wall"
0FF02 B5CB0000000000 00i64 52149
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
c390 B
stardust_document *patch = NULL;
stardust_result *failed = NULL;
uint32_t status = stardust_parse(patch_text, STARDUST_TRON, &patch);
if (status != STARDUST_OK) {stardust_document_release(patch); return status;}
status = stardust_db_merge_patch(db, patch, NULL, NULL, &failed);
stardust_document_release(patch);
stardust_diagnostic_view result = {0};
stardust_result_error(failed, &result);
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

patch_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
c716 B
stardust_document *future = NULL;
stardust_document *patch = NULL;
stardust_result *committed = NULL;
uint32_t status = stardust_parse(future_text, STARDUST_TRON, &future);
if (status == STARDUST_OK) status = stardust_parse(patch_text, STARDUST_TRON, &patch);
if (status == STARDUST_OK) status = stardust_db_merge_patch(db, future, NULL, NULL, &committed);
stardust_result_release(committed);
stardust_document_release(future);
if (status != STARDUST_OK) {stardust_document_release(patch); return status;}
stardust_result *failed = NULL;
status = stardust_db_merge_patch(db, patch, NULL, NULL, &failed);
stardust_document_release(patch);
stardust_diagnostic_view result = {0};
stardust_result_error(failed, &result);
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

Also calls: stardust_db_result_commit_info, stardust_result_error, stardust_result_release

stardust_db_indexes_sync

c75 B
uint32_t stardust_db_indexes_sync(stardust_db *db, int64_t max_wait_ticks);

Parameters

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.
max_wait_ticksint64_tValueRequiredValue passed to the call.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTmax_wait is negative
STARDUST_TIMEOUTmax_wait passed first
STARDUST_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

c542 B
stardust_result *listed = NULL;
stardust_bytes kind = {(const uint8_t *)"queries", 7};
stardust_bytes pattern = {(const uint8_t *)"people/.*", 9};
uint32_t status = stardust_db_indexes_sync(db, 50000000);
if (status == STARDUST_OK) status = stardust_db_definition_list(db, kind, pattern, &listed);
if (status != STARDUST_OK) { stardust_result_release(listed); return status; }
stardust_document *result = NULL;
status = stardust_result_take_document(listed, &result);
stardust_result_release(listed);
if (status != STARDUST_OK) return status;
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

stardust_db_bulk_begin

c49 B
uint32_t stardust_db_bulk_begin(stardust_db *db);

Parameters

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTa bulk build is already in progress on the database
STARDUST_CLOSEDthe database is closed
STARDUST_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

c282 B
uint32_t status = stardust_db_bulk_begin(db);
if (status != STARDUST_OK) return status;
// A second build on the same database is refused while this one runs.
if (stardust_db_bulk_begin(db) != STARDUST_INVALID_ARGUMENT) return STARDUST_EVALUATION_FAILED;
stardust_db_bulk_abort(db);

stardust_db_bulk_add

c79 B
uint32_t stardust_db_bulk_add(stardust_db *db, const stardust_document *patch);

Parameters

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.
patchconst stardust_document *Borrowed handleRequiredOne 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
STARDUST_INVALID_ARGUMENTno bulk build is in progress
STARDUST_REJECTEDthe database refuses the patch; the build has failed and later adds report the same status
STARDUST_CLOSEDthe database is closed
STARDUST_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

c826 B
// The first entity of an empty database is 1, so the second patch updates it.
const char *patches[] = {"{\"#_ada\":{\"name\":\"Ada\"}}", "{\"1\":{\"title\":\"Countess\"}}"};
stardust_result *finished = NULL;
uint32_t status = stardust_db_bulk_begin(db);
for (size_t index = 0; status == STARDUST_OK && index < 2; index++) {
    stardust_bytes patch = {(const uint8_t *)patches[index], (int64_t)strlen(patches[index])};
    stardust_document *document = NULL;
    status = stardust_parse(patch, STARDUST_JSON, &document);
    if (status == STARDUST_OK) status = stardust_db_bulk_add(db, document);
    stardust_document_release(document);
}
if (status == STARDUST_OK) status = stardust_db_bulk_finish(db, &finished);
else stardust_db_bulk_abort(db);
stardust_result_release(finished);
if (status != STARDUST_OK) return status;

stardust_db_bulk_finish

c76 B
uint32_t stardust_db_bulk_finish(stardust_db *db, stardust_result **output);
c92 B
uint32_t stardust_result_take_document(stardust_result *result, stardust_document **output);
c96 B
uint32_t stardust_result_error(const stardust_result *result, stardust_diagnostic_view *output);
c54 B
void stardust_result_release(stardust_result *result);

Parameters

stardust_db_bulk_finish

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_result **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_take_document

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_document **Owned outputRequiredReceives a library-owned handle. Release it after use.

stardust_result_error

ParameterTypeOwnershipDefaultMeaning
resultconst stardust_result *Borrowed handleRequiredKeep the handle alive until the call returns.
outputstardust_diagnostic_view *Caller-owned outputRequiredReceives a record. Its pointer fields follow the record's ownership contract.

stardust_result_release

ParameterTypeOwnershipDefaultMeaning
resultstardust_result *Consumed handleNULLEnds ownership. Do not use the handle after this call.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTno bulk build is in progress
STARDUST_REJECTEDthe database refuses a patch; an initial build publishes nothing and fallback keeps earlier commits
STARDUST_CONFLICTanother write committed to the database during the build
STARDUST_CLOSEDthe database is closed
STARDUST_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

c928 B
const char *text = "{\"#_ada\":{\"name\":\"Ada\",\"title\":\"Countess\"}}";
stardust_bytes patch = {(const uint8_t *)text, (int64_t)strlen(text)};
stardust_result *finished = NULL;
stardust_document *summary = NULL;
uint32_t status = stardust_db_bulk_begin(db);
stardust_document *document = NULL;
if (status == STARDUST_OK) status = stardust_parse(patch, STARDUST_JSON, &document);
if (status == STARDUST_OK) status = stardust_db_bulk_add(db, document);
stardust_document_release(document);
// finish ends the build also when it fails.
if (status == STARDUST_OK) status = stardust_db_bulk_finish(db, &finished);
else stardust_db_bulk_abort(db);
if (status == STARDUST_OK) status = stardust_result_take_document(finished, &summary);
stardust_result_release(finished);
// summary holds status, patches, transactions, facts, entities and phase timings.
stardust_document_release(summary);
if (status != STARDUST_OK) return status;

Also calls: stardust_result_take_document, stardust_result_error, stardust_result_release

stardust_db_bulk_abort

c45 B
void stardust_db_bulk_abort(stardust_db *db);

Parameters

ParameterTypeOwnershipDefaultMeaning
dbstardust_db *Borrowed handleNULLKeep the handle alive until the call returns.

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

c527 B
const char *text = "{\"#_ada\":{\"name\":\"Ada\"}}";
stardust_bytes patch = {(const uint8_t *)text, (int64_t)strlen(text)};
uint32_t status = stardust_db_bulk_begin(db);
stardust_document *document = NULL;
if (status == STARDUST_OK) status = stardust_parse(patch, STARDUST_JSON, &document);
if (status == STARDUST_OK) status = stardust_db_bulk_add(db, document);
stardust_document_release(document);
// Abort writes nothing; without a build it does nothing.
stardust_db_bulk_abort(db);
if (status != STARDUST_OK) return status;

stardust_db_subscription_set_notify

c59 B
typedef void (*stardust_db_subscription_notify)(void *ctx);
c127 B
uint32_t stardust_db_subscription_set_notify(stardust_db_subscription *sub, stardust_db_subscription_notify notify, void *ctx);

Parameters

ParameterRequirementMeaning
subRequiredSubscription receiving the callback. Use the handle exclusively during registration.
notifyRequiredReadiness callback.
ctxNULL is validCaller-owned state, passed unchanged to the callback. Stardust does not read or free it.

Notes

Use this optional callback to wake a host scheduler without polling or a dedicated waiting thread. Blocking next works without registration.

Register a borrowed signal-only C callback once, before any next call. NULL context is valid. Native registration allocates nothing. Install the application waiter before next with zero wait; TIMEOUT arms a coalesced readiness hint. The callback may run on any thread, must return promptly, and must not call Stardust or run application work. Keep callback code and context valid until subscription release returns; no callback is running or can run afterward. Concurrent next calls race for events. A null subscription or callback, duplicate registration, or registration after next reports invalid_argument. A failed subscription preserves its saved failure. A rejected registration retains nothing.

The example requires a C implementation with C11 threads (<threads.h>) and timed condition waits.

Examples

Wait through a readiness callback

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
c2.6 kB
#include <threads.h>
#include <time.h>
#include <stdlib.h>

struct subscription_waiter {
    mtx_t mutex;
    cnd_t changed;
    uint64_t generation;
};

static void notify_sync_check(int status) {
    if (status != thrd_success) abort();
}

static void subscription_ready(void *ctx) {
    struct subscription_waiter *waiter = ctx;
    notify_sync_check(mtx_lock(&waiter->mutex));
    waiter->generation++;
    notify_sync_check(cnd_broadcast(&waiter->changed));
    notify_sync_check(mtx_unlock(&waiter->mutex));
}

struct subscription_waiter waiter = {0};
if (mtx_init(&waiter.mutex, mtx_plain) != thrd_success) return STARDUST_OUT_OF_MEMORY;
if (cnd_init(&waiter.changed) != thrd_success) {
    mtx_destroy(&waiter.mutex);
    return STARDUST_OUT_OF_MEMORY;
}
stardust_document *definition = NULL;
stardust_db_query *query = NULL;
stardust_db_subscription *subscription = NULL;
stardust_db_live_event event = {0};
uint32_t status = stardust_parse(query_text, STARDUST_TRON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(db, &source, &query);
if (status == STARDUST_OK) status = stardust_db_query_subscribe(query, NULL, NULL, &subscription);
if (status == STARDUST_OK) status = stardust_db_subscription_set_notify(subscription, subscription_ready, &waiter);
struct timespec deadline = {0};
if (timespec_get(&deadline, TIME_UTC) != TIME_UTC) status = STARDUST_INVALID_ARGUMENT;
deadline.tv_sec += 5;
while (status == STARDUST_OK) {
    notify_sync_check(mtx_lock(&waiter.mutex));
    uint64_t observed = waiter.generation;
    notify_sync_check(mtx_unlock(&waiter.mutex));
    status = stardust_db_subscription_next(subscription, 0, &event);
    if (status != STARDUST_TIMEOUT) break;
    notify_sync_check(mtx_lock(&waiter.mutex));
    int waited = thrd_success;
    while (waiter.generation == observed && waited == thrd_success)
        waited = cnd_timedwait(&waiter.changed, &waiter.mutex, &deadline);
    notify_sync_check(mtx_unlock(&waiter.mutex));
    if (waited == thrd_success) status = STARDUST_OK;
    else if (waited != thrd_timedout) status = STARDUST_INVALID_ARGUMENT;
}
// Release joins callbacks before the stack context or its mutex is destroyed.
stardust_db_subscription_release(subscription);
stardust_db_query_release(query);
stardust_document_release(definition);
cnd_destroy(&waiter.changed);
mtx_destroy(&waiter.mutex);
if (status != STARDUST_OK) {stardust_document_release(event.result); return status;}
stardust_document *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

stardust_db_query_options

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

Note

Supply size and version with each record. NULL options select the defaults of the call.

FieldC typeUnitRangeDefaultMeaning
sizeuint32_tBytesUnsigned u32Required: sizeof(stardust_db_query_options)—
versionuint32_tNoneUnsigned u32Required: 1—
page_sizeuint32_tCountUnsigned u320 selects the default page sizeRows per page. 0 selects the default page size. Queries only.
reserveduint32_tNoneUnsigned u320Must be zero.
max_cost_ticksint64_t100 ns ticksSigned i640 selects the dynamic CPU budgetThread CPU duration limit. 0 selects the engine’s dynamic budget.
as_ofint64_tNoneSigned i64ZeroA positive transaction runs a stored definition as of that transaction.

stardust_db_write_options

Note

Supply size and version with each record. NULL options select the defaults of the call.

FieldC typeUnitRangeDefaultMeaning
sizeuint32_tBytesUnsigned u32Required: sizeof(stardust_db_write_options)—
versionuint32_tNoneUnsigned u32Required: 1—
max_cost_ticksint64_t100 ns ticksSigned i640 selects the dynamic CPU budgetThread CPU duration limit. 0 selects the engine’s dynamic budget.
as_ofint64_tNoneSigned i64ZeroA positive transaction runs a stored definition as of that transaction.

stardust_db_commit_info

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

FieldC typeUnitRangeDefaultMeaning
statusuint32_tNoneUnsigned u32The call sets it—
reserveduint32_tNoneUnsigned u320Must be zero.
transactionint64_tNoneSigned i64The call sets itZero when nothing was written.
factsint64_tCountSigned i64The call sets it—
committed_at_ticksint64_t100 ns ticks since the Unix epoch (UTC)Signed i64The call sets itRecorded commit time as a UTC instant. The call measures this value. Independent calls can differ.

stardust_db_live_event

This record contains the result of subscription next.

FieldC typeUnitRangeMeaning
sequenceint64_tCountSigned i64Event number. Event 1 is the initial result.
supersededint64_tCountSigned i64Intermediate 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.
transactionint64_tNoneSigned i64Transaction the result was computed at.
resultstardust_document *NoneC type rangeThe full query result. The event owns it and the consumer closes it.