Overview

You start with the people document, store its entities, and read their names through a query. Later pages use the same people to explain each step of that sequence.

Before you create resources, activate the core with your license token.

Example

The example follows the complete call sequence, including the release of each result.

Store people and query their names

seed_text holds this document:

json333 B
{
  "#_ada": {
    "name": "Ada",
    "role": "engineer",
    "age": 36
  },
  "#_bob": {
    "name": "Bob",
    "role": "engineer",
    "age": 41,
    "mentor": {
      "#link": "#_ada"
    }
  },
  "#_cy": {
    "name": "Cy",
    "role": "designer",
    "age": 29
  },
  "#_tx": {
    "author": "smoke",
    "reason": "seed"
  }
}

query_text holds this document:

json134 B
{
  "find": [
    "?name"
  ],
  "where": [
    [
      "?e",
      "name",
      "?name"
    ]
  ],
  "orderBy": [
    "?name"
  ]
}
c1.5 kB
stardust_db *opened = NULL;
stardust_document *seed = NULL;
stardust_document *definition = NULL;
stardust_result *seeded = NULL;
stardust_db_query *query = NULL;
stardust_db_rows *rows = NULL;
stardust_result *page = NULL;
stardust_document *result = NULL;
stardust_bytes path = {(const uint8_t *)database_path, (int64_t)strlen(database_path)};
stardust_result *opening = NULL;
uint32_t status = stardust_db_open(path, NULL, &opened, &opening);
stardust_result_release(opening);
if (status == STARDUST_OK) status = stardust_parse(seed_text, STARDUST_JSON, &seed);
if (status == STARDUST_OK) status = stardust_db_merge_patch(opened, seed, NULL, NULL, &seeded);
if (status == STARDUST_OK) status = stardust_parse(query_text, STARDUST_JSON, &definition);
stardust_db_source source = {.kind = STARDUST_SOURCE_DOCUMENT, .document = definition};
if (status == STARDUST_OK) status = stardust_db_query_open(opened, &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);
stardust_result_release(seeded);
stardust_document_release(seed);
stardust_db_close(opened);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
Result / 82 B
[
  {
    "name": "Ada"
  },
  {
    "name": "Bob"
  },
  {
    "name": "Cy"
  }
]

Ownership and lifetimes

ValueLifetimeYour action
Owned resultUntil you release itRelease it when you finish with it.
Borrowed valueThe lifetime that its operation statesStop using it when that lifetime ends.
Owned documentContinues after you release the handle that produced itRelease it separately from that handle.

Each operation states its ownership rule. Use that rule to find the values that you must release.

Concurrency

Calls can overlap unless an operation requires exclusive use of its receiver. Each such operation states that requirement beside its signature.

  • Before you release a handle, stop the calls that can still use it.
  • An owned result has its own lifetime, so another call can use it after its producer finishes.

Terms

TermMeaning
documentA tree of native values that you can read, build, or serialize.
nodeOne value in a document, identified within that document.
handleA reference to a native resource with an explicit lifetime.
ownedA result whose lifetime you control and whose release you must arrange.
borrowedA value whose lifetime depends on its stated owner.
absentA value or field that the operation does not supply.
entityA database object identified independently of its field values.
transactionA committed database change that orders the recorded facts.
factA recorded field value associated with an entity and a transaction.
variableA named value supplied to an expression or document operation.
clauseOne part of a query or mutation document that specifies its behavior.
tickThe ABI unit for a duration or UTC instant: 100 ns. Time and units defines it.

Operations

OperationReturnsSummary
stardust_abi_versionuint32_tversion() returns the loaded library's ABI version.
check_versionUnavailablecheck_version(found) verifies that found matches this binding's ABI version.
stardust_pluginsStatus. document through outputplugins() returns an owned array document describing the plugins this library can use, followed by any unavailable plugin libraries.
stardust_activateStatus. none through outputactivate(token) verifies a license token and licenses this process.
stardust_licenseStatus. license through outputlicense() returns the process license state.

stardust_abi_version

c36 B
uint32_t stardust_abi_version(void);

Parameters

This call has no parameters.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Examples

version

c40 B
int64_t result = stardust_abi_version();
Result / 1 B
1

version

c128 B
uint32_t found = stardust_abi_version();
if (found != STARDUST_ABI_VERSION) return STARDUST_UNSUPPORTED;
int64_t result = found;
Result / 1 B
1

check_version

Compare stardust_abi_version with STARDUST_ABI_VERSION.

Also calls: stardust_abi_version

stardust_plugins

c52 B
uint32_t stardust_plugins(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_plugins

ParameterTypeOwnershipDefaultMeaning
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_OUT_OF_MEMORYnative memory is exhausted
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Examples

Read the compiled plugin inventory

c318 B
stardust_result *inventory = NULL;
stardust_document *result = NULL;
uint32_t status = stardust_plugins(&inventory);
if (status == STARDUST_OK) status = stardust_result_take_document(inventory, &result);
stardust_result_release(inventory);
if (status != STARDUST_OK) {stardust_document_release(result); return status;}
Result / 948 B
[
  {
    "name": "history",
    "description": "History retention: purges entity history by each stardust/history setting",
    "version": "1",
    "willNotWorkWith": [
      "backups"
    ],
    "databaseHooks": true
  },
  {
    "name": "adaptive_query_planner",
    "description": "Adaptive join orders: learns from runs and stores the plans that proved better",
    "version": "1",
    "databaseHooks": true
  },
  {
    "name": "objects",
    "description": "Object store: content-addressed payloads in named files and directories",
    "version": "1",
    "databaseHooks": true
  },
  {
    "name": "reactors",
    "description": "Live mutations: stored mutations with live: true react to commits",
    "version": "1",
    "databaseHooks": true
  },
  {
    "name": "sdk",
    "description": "SDK generation: publishes a typed package of the stored definitions while the database is open",
    "version": "1",
    "databaseHooks": true
  }
]

Also calls: stardust_result_take_document, stardust_result_error, stardust_result_release

stardust_activate

c49 B
uint32_t stardust_activate(stardust_bytes token);
c57 B
uint32_t stardust_license(stardust_license_view *output);

Parameters

stardust_activate

ParameterTypeOwnershipDefaultMeaning
tokenstardust_bytesValueRequiredThe PASETO v4.public license token text.

stardust_license

ParameterTypeOwnershipDefaultMeaning
outputstardust_license_view *Caller-owned outputRequiredInitialize its size/version header. Returned pointers borrow the source owner.

Errors

StatusWhen
STARDUST_UNLICENSEDthe token is refused; the error names the reason
STARDUST_INVALID_ARGUMENTthe token is empty or longer than 4096 bytes

Notes

A refused token preserves the current license. Activation is required before parsing, building resources or opening a database. Existing resources keep working after license replacement or expiry.

Examples

Activate the license from a token file

c569 B
char token[4097];
FILE *file = fopen("license.token", "rb");
if (file == NULL) return STARDUST_INVALID_ARGUMENT;
size_t length = fread(token, 1, sizeof token, file);
fclose(file);
while (length > 0 && (token[length - 1] == '\n' || token[length - 1] == '\r')) length--;
stardust_bytes bytes = {(const uint8_t *)token, (int64_t)length};
stardust_license_view result = {.size = sizeof(stardust_license_view), .version = 1};
uint32_t status = stardust_activate(bytes);
if (status == STARDUST_OK) status = stardust_license(&result);
if (status != STARDUST_OK) return status;
Result / 234 B
{
  "active": true,
  "failure": "none",
  "support_end": 72580320000000000,
  "expires": null,
  "build": null,
  "refused_support_end": null,
  "subject": "test",
  "license_id": "test",
  "name": "",
  "license": "",
  "tier": ""
}

Also calls: stardust_license

stardust_license

c57 B
uint32_t stardust_license(stardust_license_view *output);

Parameters

ParameterTypeOwnershipDefaultMeaning
outputstardust_license_view *Caller-owned outputRequiredInitialize its size/version header. Returned pointers borrow the source owner.

Errors

StatusWhen
STARDUST_INVALID_ARGUMENTa required input or output pointer is NULL, or an input owner is not ready

Examples

Read the process license

c172 B
stardust_license_view result = {.size = sizeof(stardust_license_view), .version = 1};
uint32_t status = stardust_license(&result);
if (status != STARDUST_OK) return status;
Result / 234 B
{
  "active": true,
  "failure": "none",
  "support_end": 72580320000000000,
  "expires": null,
  "build": null,
  "refused_support_end": null,
  "subject": "test",
  "license_id": "test",
  "name": "",
  "license": "",
  "tier": ""
}

stardust_license_view

This record contains the result of license. Text fields are copies.

Note

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

FieldC typeUnitRangeDefaultMeaning
sizeuint32_tBytesUnsigned u32Required: sizeof(stardust_license_view)—
versionuint32_tNoneUnsigned u32Required: 1—
activeuint32_tNoneUnsigned u32The call sets itThe process holds a verified license.
failureuint32_tNoneUnsigned u32The call sets itWhy the last activation failed; none when it succeeded or none was tried.
support_end_ticksint64_t100 ns ticksSigned i64The call sets itThe last build date the license covers, as a UTC instant.
expires_ticksint64_t100 ns ticksSigned i64The call sets itThe expiry checked at activation and database open, as a UTC instant. Existing resources keep working.
build_ticksint64_t100 ns ticksSigned i64The call sets itThe build date of this library, at UTC midnight.
refused_support_end_ticksint64_t100 ns ticksSigned i64The call sets itThe support end of the token the last activation refused as support_ended, as a UTC instant.
subjectstardust_bytesNoneC type rangeThe call sets itThe OAuth sign-in identity of the license. Empty when not active.
license_idstardust_bytesNoneC type rangeThe call sets itThe unique license token ID. Empty when not active.
namestardust_bytesNoneC type rangeThe call sets itThe project name, or account display name for Community. Empty when absent.
licensestardust_bytesNoneC type rangeThe call sets itThe ID of the purchased license, a ULID. Empty when absent.
tierstardust_bytesNoneC type rangeThe call sets itThe license tier: community, solo or team. Empty when absent.