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:

edn287 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:

edn66 B
{:find    [?name]
 :where   [[?e "name" ?name]]
 :orderBy [?name]}
clojure260 B
(with-open [db (sd/open database-path)
            seed (sd/parse seed-text :edn)
            definition (sd/parse query-text :edn)]
  (sd/merge-patch db seed)
  (with-open [query (sd/query db definition)
              rows (sd/run query)]
    (sd/next rows)))
Result / 51 B
{:value [{: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
versionversionversion() returns the loaded library's ABI version.
check-versionnonecheck_version(found) verifies that found matches this binding's ABI version.
pluginsdocumentplugins() returns an owned array document describing the plugins this library can use, followed by any unavailable plugin libraries.
activatenoneactivate(token) verifies a license token and licenses this process.
licenselicenselicense() returns the process license state.

version

clojure2 B
[]
clojure9 B
[options]

Parameters

ParameterTypeOwnershipDefaultMeaning
optionsmapValue{}Binding options map. The :library key selects the loaded native library. Omission uses the binding's default library.

Examples

version

clojure12 B
(sd/version)
Result / 10 B
{:value 1}

C exports: stardust_abi_version

check-version

clojure7 B
[found]

Parameters

ParameterTypeOwnershipDefaultMeaning
foundVersionValueRequiredThe ABI version to compare with this binding.

Errors

StatusWhen
:unsupportedfound differs from the ABI version of the binding

Examples

check_version

clojure36 B
(doto (sd/version) sd/check-version)
Result / 10 B
{:value 1}

C exports: stardust_abi_version

plugins

clojure2 B
[]
clojure9 B
[options]

Parameters

ParameterTypeOwnershipDefaultMeaning
optionsmapValue{}Binding options map. The :library key selects the loaded native library. Omission uses the binding's default library.

Errors

StatusWhen
:out-of-memorynative memory is exhausted

Examples

Read the compiled plugin inventory

clojure12 B
(sd/plugins)
Result / 940 B
{:value [
   {: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}]}

C exports: stardust_plugins, stardust_result_take_document, stardust_result_error, stardust_result_release

activate

clojure7 B
[token]
clojure15 B
[token options]

Parameters

ParameterTypeOwnershipDefaultMeaning
tokenNameValueRequiredThe PASETO v4.public license token text.
optionsmapValue{}Binding options map. The :library key selects the loaded native library. Omission uses the binding's default library.

Errors

StatusWhen
:unlicensedthe token is refused; the error names the reason
: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

clojure73 B
(do (sd/activate (string/trim (slurp "license.token")))
    (sd/license))
Result / 396 B
{:value {:active              true
         :failure             "none"
         :support_end         72580320000000000
         :expires             nil
         :build               nil
         :refused_support_end nil
         :subject             "test"
         :license_id          "test"
         :name                ""
         :license             ""
         :tier                ""}}

C exports: stardust_activate, stardust_license

license

clojure2 B
[]
clojure9 B
[options]

Parameters

ParameterTypeOwnershipDefaultMeaning
optionsmapValue{}Binding options map. The :library key selects the loaded native library. Omission uses the binding's default library.

Examples

Read the process license

clojure12 B
(sd/license)
Result / 396 B
{:value {:active              true
         :failure             "none"
         :support_end         72580320000000000
         :expires             nil
         :build               nil
         :refused_support_end nil
         :subject             "test"
         :license_id          "test"
         :name                ""
         :license             ""
         :tier                ""}}

C exports: stardust_license

license_info

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

FieldTypeUnitRangeAbsentMeaning
activeBoolNoneHost type range—The process holds a verified license.
failureLicense-FailureNoneHost type range—Why the last activation failed; none when it succeeded or none was tried.
support_endInstantUTC instant (100 ns ticks since the Unix epoch at the ABI)Tick rangenilThe last build date the license covers, as a UTC instant.
expiresInstantUTC instant (100 ns ticks since the Unix epoch at the ABI)Tick rangenilThe expiry checked at activation and database open, as a UTC instant. Existing resources keep working.
buildInstantUTC instant (100 ns ticks since the Unix epoch at the ABI)Tick rangenilThe build date of this library, at UTC midnight.
refused_support_endInstantUTC instant (100 ns ticks since the Unix epoch at the ABI)Tick rangenilThe support end of the token the last activation refused as support_ended, as a UTC instant.
subjectCopied-TextNoneHost type range—The OAuth sign-in identity of the license. Empty when not active.
license_idCopied-TextNoneHost type range—The unique license token ID. Empty when not active.
nameCopied-TextNoneHost type range—The project name, or account display name for Community. Empty when absent.
licenseCopied-TextNoneHost type range—The ID of the purchased license, a ULID. Empty when absent.
tierCopied-TextNoneHost type range—The license tier: community, solo or team. Empty when absent.