SDK generation
The SDK plugin generates a typed package from the database's stored definitions. While the database is open, it updates that package in the configured output directory.
The generated code calls the language binding and provides typed access to stored definitions.
Enable sdk in the plugin selection at open, with the output settings below.
Calls without it report the unavailable status.
Query results recursively omit fields containing empty objects or arrays.
Generated rows keep zero values for absent fields, such as nil for an any field.
Null, empty strings, false, zero and array positions stay intact in the returned document.
Native time values
Generated native time fields use
time.Time for timestamps and time.Duration for durations.
Use stardust.InstantFromTicks, InstantToTicks, DurationFromTicks and DurationToTicks for native tick conversion.
The explicit tick conversions refuse precision loss and values outside the target range. These conversions perform no native operation.
A native time schema requires one string member, #utc or #dur, and sets additionalProperties to false.
For example, this schema describes a native timestamp:
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 00 | 54 52 4F 4E | magic TRON |
| 04 | 4C 74797065 | txt "type" |
| 09 | 6C 737472696E67 | txt "string" |
| 10 | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 1A | 4C 23757463 | txt "#utc" |
| 1F | 0F 0A 1A000000 1000 0000 | map leaf, size 10: @1A → @10 |
| 29 | 4C 23757463 | txt "#utc" |
| 2E | 0E 0D 00 0100 010000 00 29000000 | array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @29 |
| 3B | AC 70726F70657274 696573 | txt "properties" |
| 46 | 0F 0A 3B000000 1F00 0000 | map leaf, size 10: @3B → @1F |
| 50 | 8C 72657175697265 64 | txt "required" |
| 59 | 0F 0A 50000000 2E00 0000 | map leaf, size 10: @50 → @2E |
| 63 | 14 14 616464697469 6F6E616C50726F70 657274696573 | txt "additionalProperties" |
| 79 | 01 | bit false |
| 7A | 0F 0A 63000000 7900 0000 | map leaf, size 10: @63 → @79 |
| 84 | 4C 74797065 | txt "type" |
| 89 | 6C 6F626A656374 | txt "object" |
| 90 | 0F 0A 84000000 8900 0000 | map leaf, size 10: @84 → @89 |
| 9A | 07 16 A8040000 4600 0000 59000000 7A00 0000 90000000 | map branch, size 22, depth 0 (root), slots 3, 5, 7, 10: @46 → @59 → @7A → @90 |
| B0 | 9A000000 00000000 | root → @9A; previous: none |
Use #dur in both places for a duration schema.
Schema fields support lists and stored-schema references.
Scalar time fields also type query filters and rows.
Native time expression results use the same binding types.
An ordinary string schema stays text, including strings with a date-time format.
Native ticks are signed 64-bit counts of 100 ns.
Timestamp ticks count from the Unix epoch in UTC. Duration ticks can be negative.
Settings
Set go.dir to a dedicated directory for the generated packages:
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 00 | 54 52 4F 4E | magic TRON |
| 04 | 3C 646972 | txt "dir" |
| 08 | AC 67656E2F70656F 706C65 | txt "gen/people" |
| 13 | 0F 0A 04000000 0800 0000 | map leaf, size 10: @4 → @8 |
| 1D | 4C 23647572 | txt "#dur" |
| 22 | 7C 5054302E323553 | txt "PT0.25S" |
| 2A | 0F 0A 1D000000 2200 0000 | map leaf, size 10: @1D → @22 |
| 34 | 4C 23647572 | txt "#dur" |
| 39 | 4C 50543253 | txt "PT2S" |
| 3E | 0F 0A 34000000 3900 0000 | map leaf, size 10: @34 → @39 |
| 48 | 8C 6D61785F776169 74 | txt "max_wait" |
| 51 | 0F 0A 48000000 3E00 0000 | map leaf, size 10: @48 → @3E |
| 5B | 8C 6465626F756E63 65 | txt "debounce" |
| 64 | 0F 0A 5B000000 2A00 0000 | map leaf, size 10: @5B → @2A |
| 6E | 2C 676F | txt "go" |
| 71 | 0F 0A 6E000000 1300 0000 | map leaf, size 10: @6E → @13 |
| 7B | 07 12 25000000 5100 0000 64000000 7100 0000 | map branch, size 18, depth 0 (root), slots 0, 2, 5: @51 → @64 → @71 |
| 8D | 3C 73646B | txt "sdk" |
| 91 | 0F 0A 8D000000 7B00 0000 | map leaf, size 10: @8D → @7B |
| 9B | 91000000 00000000 | root → @91; previous: none |
| Member | Value | Result |
|---|---|---|
go.dir | Directory path | A dedicated directory for the generated packages. The plugin controls all its contents. A relative path is relative to the working directory of the process at open. A missing directory is created. |
debounce | #dur duration, PT0.25S when absent | How long definition commits must stay quiet before the plugin generates again. |
max_wait | #dur duration, PT2S when absent | The longest wait after the first definition commit. |
Without the go member, the plugin publishes no Go files.
Settings apply only to the database that is open. To change them, open the database again.
Runs
The plugin generates once at open, and again after commits that change definitions. Data commits do not start a run. A run reads all definitions from one committed snapshot.
Each successful render replaces the output directory's contents, including the startup run. See file ownership before choosing an output directory.
Call status to inspect these fields:
| Field | Contents |
|---|---|
enabled | Whether the plugin is enabled |
pending | Whether generation remains |
runs | Run count |
fingerprint | Generation model fingerprint |
outputs | Outputs, each with language, directory and file counts written and removed |
diagnostics | Diagnostics with severity, code, definition type and path, pointer, member, language and message |
failure | Last run failure, with code and message; absent after a successful run |
When to call sync
Generation runs automatically at open and after definition commits, according to the debounce settings. Opening the database or committing definitions can finish before the generated files are ready. Call sync before compiling or reading files that must include those definitions. Applications that can use the files after automatic generation finishes do not need an explicit sync.
The call requests a render immediately, bypassing debounce. It also rebuilds files when definitions have not changed.
Its options accept only the common maxWait option. A timeout leaves the requested run active.
Repeated waits after a timeout join that run. Inspect status when generation reports failed.
Without an output language, sync validates the model inline and writes no files.
The Go packages
The plugin writes one Go package for each definition type that has definitions, in a subdirectory of go.dir named after the type.
The generated names belong to your definitions, so they live in these packages and not in the stardust binding package.
Each package also declares ModelFingerprint, which identifies the definitions that the packages were generated from.
schemas: one struct for each object schema, with a field for each property andjsontags. An optional scalar property is a pointer withomitempty. A property that refers to another stored object schema with$refis a pointer to its struct. Native time references use the time types described above. Other non-object references useany.queries: for each stored query, a row struct, a parameter struct when the query has inputs, and a function that runs the query and returnsiter.Seq2over decoded rows. When the shape of the row is not known before the query runs, for example withresultMode positional, the row type isany.mutations: for each stored mutation, a parameter struct and a function that runs the mutation and returns its commit information.expressions: for each stored expression, a parameter struct and a function that evaluates it with the stored macros of the database and decodes its result.
The inputs of a query or mutation are its parameters and its other variables:
- A declared parameter is a pointer with
omitempty. Anilpointer keeps the stored default. A non-nil pointer supplies the value, including an empty collection. A supplied null parameter reportsmissing_parameter. - A variable that appears only in a predicate, such as
?maxin[<= ?age ?max], is a required parameter and not a pointer. - Every other variable bound by the query clauses is an optional filter, a pointer with
omitempty. Anilfilter leaves the variable unbound, so it matches any value. A value binds the variable before the query runs, so the rows narrow to that value. An entity variable, such as?itemin[?item key ?key], is a*stardust.Link.
The query calculates aggregate and window result variables after the clauses run. These variables are not filter inputs.
For example, these definitions:
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 000 | 54 52 4F 4E | magic TRON |
| 004 | 4C 74797065 | txt "type" |
| 009 | 6C 737472696E67 | txt "string" |
| 010 | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 01A | 4C 74797065 | txt "type" |
| 01F | 7C 696E7465676572 | txt "integer" |
| 027 | 0F 0A 1A000000 1F00 0000 | map leaf, size 10: @1A → @1F |
| 031 | 3C 616765 | txt "age" |
| 035 | 0F 0A 31000000 2700 0000 | map leaf, size 10: @31 → @27 |
| 03F | 4C 6E616D65 | txt "name" |
| 044 | 0F 0A 3F000000 1000 0000 | map leaf, size 10: @3F → @10 |
| 04E | 07 0E 00810000 3500 0000 44000000 | map branch, size 14, depth 0 (root), slots 8, 15: @35 → @44 |
| 05C | 4C 6E616D65 | txt "name" |
| 061 | 0E 0D 00 0100 010000 00 5C000000 | array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @5C |
| 06E | AC 70726F70657274 696573 | txt "properties" |
| 079 | 0F 0A 6E000000 4E00 0000 | map leaf, size 10: @6E → @4E |
| 083 | 8C 72657175697265 64 | txt "required" |
| 08C | 0F 0A 83000000 6100 0000 | map leaf, size 10: @83 → @61 |
| 096 | 4C 74797065 | txt "type" |
| 09B | 6C 6F626A656374 | txt "object" |
| 0A2 | 0F 0A 96000000 9B00 0000 | map leaf, size 10: @96 → @9B |
| 0AC | 07 12 28040000 7900 0000 8C000000 A200 0000 | map branch, size 18, depth 0 (root), slots 3, 5, 10: @79 → @8C → @A2 |
| 0BE | 5C 3F6E616D65 | txt "?name" |
| 0C4 | 0E 0D 00 0100 010000 00 BE000000 | array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @BE |
| 0D1 | 3C 6D696E | txt "min" |
| 0D5 | 02 12000000000000 00 | i64 18 |
| 0DE | 0F 0A D1000000 D500 0000 | map leaf, size 10: @D1 → @D5 |
| 0E8 | 2C 3F65 | txt "?e" |
| 0EB | 4C 6E616D65 | txt "name" |
| 0F0 | 5C 3F6E616D65 | txt "?name" |
| 0F6 | 0E 15 00 0700 030000 00 E8000000 EB0000 00 F0000000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @E8 → @EB → @F0 |
| 10B | 2C 3F65 | txt "?e" |
Show all 72 nodes
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 10E | 3C 616765 | txt "age" |
| 112 | 4C 3F616765 | txt "?age" |
| 117 | 0E 15 00 0700 030000 00 0B010000 0E0100 00 12010000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @10B → @10E → @112 |
| 12C | 2C 3E3D | txt ">=" |
| 12F | 4C 3F616765 | txt "?age" |
| 134 | 4C 3F6D696E | txt "?min" |
| 139 | 0E 15 00 0700 030000 00 2C010000 2F0100 00 34010000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @12C → @12F → @134 |
| 14E | 0E 15 00 0700 030000 00 F6000000 170100 00 39010000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @F6 → @117 → @139 |
| 163 | 5C 7768657265 | txt "where" |
| 169 | 0F 0A 63010000 4E01 0000 | map leaf, size 10: @163 → @14E |
| 173 | 4C 66696E64 | txt "find" |
| 178 | 0F 0A 73010000 C400 0000 | map leaf, size 10: @173 → @C4 |
| 182 | AC 706172616D6574 657273 | txt "parameters" |
| 18D | 0F 0A 82010000 DE00 0000 | map leaf, size 10: @182 → @DE |
| 197 | 07 12 2A000000 6901 0000 78010000 8D01 0000 | map branch, size 18, depth 0 (root), slots 1, 3, 5: @169 → @178 → @18D |
| 1A9 | 5C 3F6974656D | txt "?item" |
| 1AF | 0E 0D 00 0100 010000 00 A9010000 | array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @1A9 |
| 1BC | 5C 3F6974656D | txt "?item" |
| 1C2 | 3C 6B6579 | txt "key" |
| 1C6 | 4C 3F6B6579 | txt "?key" |
| 1CB | 0E 15 00 0700 030000 00 BC010000 C20100 00 C6010000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @1BC → @1C2 → @1C6 |
| 1E0 | 0E 0D 00 0100 010000 00 CB010000 | array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @1CB |
| 1ED | 5C 7768657265 | txt "where" |
| 1F3 | 0F 0A ED010000 E001 0000 | map leaf, size 10: @1ED → @1E0 |
| 1FD | 4C 66696E64 | txt "find" |
| 202 | 0F 0A FD010000 AF01 0000 | map leaf, size 10: @1FD → @1AF |
| 20C | 07 0E 0A000000 F301 0000 02020000 | map branch, size 14, depth 0 (root), slots 1, 3: @1F3 → @202 |
| 21A | 1C 2A | txt "*" |
| 21C | 2C 3F6E | txt "?n" |
| 21F | 02 02000000000000 00 | i64 2 |
| 228 | 0E 15 00 0700 030000 00 1A020000 1C0200 00 1F020000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @21A → @21C → @21F |
| 23D | DC 71756572696573 2F6974656D73 | txt "queries/items" |
| 24B | 0F 0A 3D020000 0C02 0000 | map leaf, size 10: @23D → @20C |
| 255 | EC 736368656D6173 2F706572736F6E | txt "schemas/person" |
| 264 | 0F 0A 55020000 AC00 0000 | map leaf, size 10: @255 → @AC |
| 26E | 07 0E 00880000 4B02 0000 64020000 | map branch, size 14, depth 1, slots 11, 15: @24B → @264 |
| 27C | 14 12 657870726573 73696F6E732F646F 75626C65 | txt "expressions/double" |
| 290 | 0F 0A 7C020000 2802 0000 | map leaf, size 10: @27C → @228 |
| 29A | EC 71756572696573 2F62795F616765 | txt "queries/by_age" |
| 2A9 | 0F 0A 9A020000 9701 0000 | map leaf, size 10: @29A → @197 |
| 2B3 | 07 12 08030000 6E02 0000 90020000 A902 0000 | map branch, size 18, depth 0 (root), slots 3, 8, 9: @26E → @290 → @2A9 |
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 2C5 | B3020000 00000000 | root → @2B3; previous: none |
give schemas.Person, queries.ByAge, queries.Items and expressions.Double with their row and parameter structs. Import each package from the module that contains go.dir:
for row, err := range queries.ByAge(db, queries.ByAgeParameters{}, stardust.RunOptions{}) {
if err != nil {
return err
}
fmt.Println(row.Name)
}
key := any("b")
for item, err := range queries.Items(db, queries.ItemsParameters{Key: &key}, stardust.RunOptions{}) {
if err != nil {
return err
}
fmt.Println(item.Item)
}
doubled, err := expressions.Double(db, expressions.DoubleParameters{N: 21})| Definition type | Go type |
|---|---|
string | string |
integer | int64 |
number | float64 |
boolean | bool |
object without a schema | map[string]any |
array | A slice of the item type |
| Native timestamp | time.Time |
| Native duration | time.Duration |
| Entity | stardust.Link |
| Not known | any |
Names
A name comes from the path of its definition: people/by_name becomes PeopleByName.
A name never depends on the other definitions, so a change to one definition never renames another.
Each definition type has its own package, so a schema and a query can have the same name.
When two definitions of one type claim one name, or one file name, or a definition claims a name that its package declares for itself, the run fails with the code Model_Errors.
A run with naming errors publishes nothing and keeps the files that the plugin published before.
status lists each error in diagnostics. Rename one of the definitions to correct it.
Go struct tags cannot represent some field names, including names with commas or backticks. Such names cause Invalid_Field. Rename the field to correct the error.
File ownership
The plugin owns the entire configured output directory. Every successful render removes its previous contents, including edited files, unrelated files and subdirectories.
Keep application source, database files and other data outside this directory.
Do not edit generated files: the next run replaces your changes.
The plugin retains only its internal .stardust-sdk.lock file between runs.
The plugin renders and validates the package before it removes any files. Rendering errors leave the previous directory contents unchanged. A filesystem error during cleanup or writing can leave the directory empty or partly written. The next successful run clears that partial output and writes a fresh package. Use sync before a build and check its result.
Each file is written through an atomic rename. Rebuilding the whole directory is not atomic.
A destination lock prevents concurrent publication and reports Destination_Busy when another publisher holds it.
Use a separate output directory for each database, with no directory nested inside another output directory.
Cleanup removes symlinks inside the output directory without following them.
The output directory itself and the lock file must not be symlinks.
Directory inspection is limited to 65,536 entries, 64 levels and 16 MiB of stored paths.
An inspection failure leaves the previous contents unchanged.
Operations
| Operation | Returns | Summary |
|---|---|---|
| Sdk.Status | document | sdk.status() returns the SDK generator's owned status document. |
| Sdk.Sync | none | sdk.sync(options) waits until the SDK generator published the definitions committed before the call. |
Sdk.Status
func (v Sdk) Status() (*Document, error)Errors
| Status | When |
|---|---|
StatusUnavailable | the database does not enable the sdk plugin |
StatusClosed | the database is closed |
StatusOutOfMemory | native memory is exhausted |
Notes
The document describes generation outputs, diagnostics and the last run: see runs.
Examples
Describe the SDK generator
syncOptions, err := stardust.Parse([]byte(`{maxWait {#dur PT5S}}`), stardust.DUST)
if err != nil {
return err
}
defer syncOptions.Close()
if err := db.Sdk().Sync(syncOptions); err != nil {
return err
}
result, err := db.Sdk().Status()
if err != nil {
return err
}
defer result.Close()| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 00 | 54 52 4F 4E | magic TRON |
| 04 | 4C 72756E73 | txt "runs" |
| 09 | 02 01000000000000 00 | i64 1 |
| 12 | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 1C | 7C 656E61626C6564 | txt "enabled" |
| 24 | 09 | bit true |
| 25 | 0F 0A 1C000000 2400 0000 | map leaf, size 10: @1C → @24 |
| 2F | 7C 70656E64696E67 | txt "pending" |
| 37 | 01 | bit false |
| 38 | 0F 0A 2F000000 3700 0000 | map leaf, size 10: @2F → @37 |
| 42 | BC 66696E67657270 72696E74 | txt "fingerprint" |
| 4E | 14 47 736861323536 3A66306531373061 6335346236376230 6639613865343739 3439323261353836 6332316461323931 3062303736366463 6433666562343130 6234313662363165 38 | txt "sha256:f0e170ac54b67b0f9…" |
| 97 | 0F 0A 42000000 4E00 0000 | map leaf, size 10: @42 → @4E |
| A1 | 07 16 280A0000 1200 0000 25000000 3800 0000 97000000 | map branch, size 22, depth 0 (root), slots 3, 5, 9, 11: @12 → @25 → @38 → @97 |
| B7 | A1000000 00000000 | root → @A1; previous: none |
C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
Sdk.Sync
func (v Sdk) Sync(options *Document) errorParameters
| Parameter | Type | Ownership | Default | Meaning |
|---|---|---|---|---|
options | *Document | Borrowed for the call | Absent selects operation defaults | The borrowed call options, or none. Optional maxWait is a nonnegative native duration, such as {maxWait {#dur PT5S}}. Without it, or with zero, the call checks once. |
Errors
| Status | When |
|---|---|
StatusInvalidArgument | options is not an object, or an option is invalid, duplicated or unsupported |
StatusFailed | the plugin's work failed; status describes the failure |
StatusTimeout | maxWait passed before the work finished |
StatusUnavailable | the database does not enable the sdk plugin |
StatusClosed | the database is closed |
Notes
Database close interrupts an active wait. See when to call sync.
Examples
Run the SDK generator and wait for it
syncOptions, err := stardust.Parse([]byte(`{maxWait {#dur PT5S}}`), stardust.DUST)
if err != nil {
return err
}
defer syncOptions.Close()
if err := db.Sdk().Sync(syncOptions); err != nil {
return err
}
result, err := db.Sdk().Status()
if err != nil {
return err
}
defer result.Close()| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 00 | 54 52 4F 4E | magic TRON |
| 04 | 4C 72756E73 | txt "runs" |
| 09 | 02 01000000000000 00 | i64 1 |
| 12 | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 1C | 7C 656E61626C6564 | txt "enabled" |
| 24 | 09 | bit true |
| 25 | 0F 0A 1C000000 2400 0000 | map leaf, size 10: @1C → @24 |
| 2F | 7C 70656E64696E67 | txt "pending" |
| 37 | 01 | bit false |
| 38 | 0F 0A 2F000000 3700 0000 | map leaf, size 10: @2F → @37 |
| 42 | BC 66696E67657270 72696E74 | txt "fingerprint" |
| 4E | 14 47 736861323536 3A66306531373061 6335346236376230 6639613865343739 3439323261353836 6332316461323931 3062303736366463 6433666562343130 6234313662363165 38 | txt "sha256:f0e170ac54b67b0f9…" |
| 97 | 0F 0A 42000000 4E00 0000 | map leaf, size 10: @42 → @4E |
| A1 | 07 16 280A0000 1200 0000 25000000 3800 0000 97000000 | map branch, size 22, depth 0 (root), slots 3, 5, 9, 11: @12 → @25 → @38 → @97 |
| B7 | A1000000 00000000 | root → @A1; previous: none |
C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release