Save definitions and generate the SDK
Create definitions/dune/houses.dust with these forms. The path below
definitions names the dune/houses namespace. This step saves only the
forms that the next two steps call. A later step adds more forms to this file.
Select DUST in the format selector when you copy the forms into this file.
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 000 | 54 52 4F 4E | magic TRON |
| 004 | 6C 236C6F63616C | txt "#local" |
| 00B | DC 61746F6D696373 2D666F756E64 | txt "atomics-found" |
| 019 | 0F 0A 04000000 0B00 0000 | map leaf, size 10: @4 → @B |
| 023 | 6C 236C6F63616C | txt "#local" |
| 02A | 4C 6E616D65 | txt "name" |
| 02F | 0F 0A 23000000 2A00 0000 | map leaf, size 10: @23 → @2A |
| 039 | 0E 0D 00 0100 010000 00 2F000000 | array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @2F |
| 046 | 6C 236C6F63616C | txt "#local" |
| 04D | 7C 737472696E673F | txt "string?" |
| 055 | 0F 0A 46000000 4D00 0000 | map leaf, size 10: @46 → @4D |
| 05F | 4C 6E616D65 | txt "name" |
| 064 | 0F 0A 5F000000 5500 0000 | map leaf, size 10: @5F → @55 |
| 06E | 6C 236C6F63616C | txt "#local" |
| 075 | 4C 6E616D65 | txt "name" |
| 07A | 0F 0A 6E000000 7500 0000 | map leaf, size 10: @6E → @75 |
| 084 | 5C 686F757365 | txt "house" |
| 08A | 09 | bit true |
| 08B | 0F 0A 84000000 8A00 0000 | map leaf, size 10: @84 → @8A |
| 095 | 4C 6E616D65 | txt "name" |
| 09A | 0F 0A 95000000 7A00 0000 | map leaf, size 10: @95 → @7A |
| 0A4 | 07 0E 08800000 8B00 0000 9A000000 | map branch, size 14, depth 0 (root), slots 3, 15: @8B → @9A |
| 0B2 | 6C 5F686F757365 | txt "_house" |
| 0B9 | 0F 0A B2000000 A400 0000 | map leaf, size 10: @B2 → @A4 |
| 0C3 | 5C 7061746368 | txt "patch" |
| 0C9 | 0F 0A C3000000 B900 0000 | map leaf, size 10: @C3 → @B9 |
| 0D3 | 6C 736368656D61 | txt "schema" |
| 0DA | 0F 0A D3000000 6400 0000 | map leaf, size 10: @D3 → @64 |
| 0E4 | 07 0E 01040000 C900 0000 DA000000 | map branch, size 14, depth 1, slots 0, 10: @C9 → @DA |
| 0F2 | 07 0A 80000000 E400 0000 | map branch, size 10, depth 0 (root), slots 7: @E4 |
| 0FC | BC 6465666D757461 74696F6E | txt "defmutation" |
| 108 | 0E 19 00 0F00 040000 00 FC000000 190000 00 39000000 F20000 00 | array leaf, size 25, shift 0, bitmap 000F, count 4 (root): @FC → @19 → @39 → @F2 |
Show all 100 nodes
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 121 | 7C 23696E766F6B65 | txt "#invoke" |
| 129 | 0F 0A 21010000 0801 0000 | map leaf, size 10: @121 → @108 |
| 133 | 6C 236C6F63616C | txt "#local" |
| 13A | 6C 686F75736573 | txt "houses" |
| 141 | 0F 0A 33010000 3A01 0000 | map leaf, size 10: @133 → @13A |
| 14B | 0E 09 00 0000 000000 00 | array leaf, size 9, shift 0, bitmap 0000, count 0 (root) |
| 154 | 6C 236C6F63616C | txt "#local" |
| 15B | 6C 3F686F757365 | txt "?house" |
| 162 | 0F 0A 54010000 5B01 0000 | map leaf, size 10: @154 → @15B |
| 16C | 5C 686F757365 | txt "house" |
| 172 | 09 | bit true |
| 173 | 0F 0A 6C010000 7201 0000 | map leaf, size 10: @16C → @172 |
| 17D | 0E 11 00 0300 020000 00 62010000 730100 00 | array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @162 → @173 |
| 18E | 6C 236C6F63616C | txt "#local" |
| 195 | 6C 736368656D61 | txt "schema" |
| 19C | 0F 0A 8E010000 9501 0000 | map leaf, size 10: @18E → @195 |
| 1A6 | 6C 236C6F63616C | txt "#local" |
| 1AD | 7C 737472696E673F | txt "string?" |
| 1B5 | 0F 0A A6010000 AD01 0000 | map leaf, size 10: @1A6 → @1AD |
| 1BF | 6C 236C6F63616C | txt "#local" |
| 1C6 | 8C 6F7074696F6E61 6C | txt "optional" |
| 1CF | 0F 0A BF010000 C601 0000 | map leaf, size 10: @1BF → @1C6 |
| 1D9 | 6C 236C6F63616C | txt "#local" |
| 1E0 | 5C 6D61796265 | txt "maybe" |
| 1E6 | 0F 0A D9010000 E001 0000 | map leaf, size 10: @1D9 → @1E0 |
| 1F0 | 6C 236C6F63616C | txt "#local" |
| 1F7 | 8C 626F6F6C65616E 3F | txt "boolean?" |
| 200 | 0F 0A F0010000 F701 0000 | map leaf, size 10: @1F0 → @1F7 |
| 20A | 0E 11 00 0300 020000 00 E6010000 000200 00 | array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @1E6 → @200 |
| 21B | 0E 11 00 0300 020000 00 CF010000 0A0200 00 | array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @1CF → @20A |
| 22C | 8C 756E7365616C65 64 | txt "unsealed" |
| 235 | 0F 0A 2C020000 1B02 0000 | map leaf, size 10: @22C → @21B |
| 23F | 4C 6E616D65 | txt "name" |
| 244 | 0F 0A 3F020000 B501 0000 | map leaf, size 10: @23F → @1B5 |
| 24E | 07 0E 10800000 3502 0000 44020000 | map branch, size 14, depth 0 (root), slots 4, 15: @235 → @244 |
| 25C | 6C 236C6F63616C | txt "#local" |
| 263 | 6C 3F686F757365 | txt "?house" |
| 26A | 0F 0A 5C020000 6302 0000 | map leaf, size 10: @25C → @263 |
| 274 | 0E 15 00 0700 030000 00 9C010000 4E0200 00 6A020000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @19C → @24E → @26A |
| 289 | 0E 11 00 0300 020000 00 7D010000 740200 00 | array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @17D → @274 |
| 29A | 8C 756E7365616C65 64 | txt "unsealed" |
| 2A3 | 09 | bit true |
| 2A4 | 0F 0A 9A020000 A302 0000 | map leaf, size 10: @29A → @2A3 |
| 2AE | 4C 6E616D65 | txt "name" |
| 2B3 | 09 | bit true |
| 2B4 | 0F 0A AE020000 B302 0000 | map leaf, size 10: @2AE → @2B3 |
| 2BE | 07 0E 10800000 A402 0000 B4020000 | map branch, size 14, depth 0 (root), slots 4, 15: @2A4 → @2B4 |
| 2CC | 6C 3F686F757365 | txt "?house" |
| 2D3 | 0F 0A CC020000 BE02 0000 | map leaf, size 10: @2CC → @2BE |
| 2DD | 5C 7768657265 | txt "where" |
| 2E3 | 0F 0A DD020000 8902 0000 | map leaf, size 10: @2DD → @289 |
| 2ED | 7C 70726F6A656374 | txt "project" |
| 2F5 | 0F 0A ED020000 D302 0000 | map leaf, size 10: @2ED → @2D3 |
| 2FF | 07 0E 02040000 E302 0000 F5020000 | map branch, size 14, depth 0 (root), slots 1, 10: @2E3 → @2F5 |
| 30D | 8C 64656671756572 79 | txt "defquery" |
| 316 | 0E 19 00 0F00 040000 00 0D030000 410100 00 4B010000 FF0200 00 | array leaf, size 25, shift 0, bitmap 000F, count 4 (root): @30D → @141 → @14B → @2FF |
| 32F | 7C 23696E766F6B65 | txt "#invoke" |
| 337 | 0F 0A 2F030000 1603 0000 | map leaf, size 10: @32F → @316 |
| 341 | 6C 236C6F63616C | txt "#local" |
| 348 | DC 61746F6D696373 2D666F756E64 | txt "atomics-found" |
| 356 | 0F 0A 41030000 4803 0000 | map leaf, size 10: @341 → @348 |
| 360 | 6C 236C6F63616C | txt "#local" |
| 367 | 6C 686F75736573 | txt "houses" |
| 36E | 0F 0A 60030000 6703 0000 | map leaf, size 10: @360 → @367 |
| 378 | 6C 6578706F7274 | txt "export" |
| 37F | 0E 15 00 0700 030000 00 78030000 560300 00 6E030000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @378 → @356 → @36E |
| 394 | 7C 23696E766F6B65 | txt "#invoke" |
| 39C | 0F 0A 94030000 7F03 0000 | map leaf, size 10: @394 → @37F |
| 3A6 | 0E 15 00 0700 030000 00 29010000 370300 00 9C030000 | array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @129 → @337 → @39C |
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 3BB | A6030000 00000000 | root → @3A6; previous: none |
The atomics-found mutation
defmutation defines a mutation, which is a function that writes to the
database. The name comes first, then the parameter vector [name], then a
body map. The patch member of the body gives the facts to write. A key that
starts with _ is a temporary name for a new entity, so _house makes a new
house.
The map of _house holds the tag <house> and the name field. A tag is a
field with the value true, so <house> is the same as {house true}. One
tag group can hold more than one tag, and it can be in the same map as other
fields. The name field gets the value of the name parameter.
The schema member checks each entity that the patch writes, after the patch.
Here, the name field must be a string. The SDK reads this schema to find the
type of the parameter that fills the field. Thus AtomicsFound accepts a Go
string. Without a schema or a contract, a generated parameter has the type
Value.
The houses query
defquery defines a query. The empty vector [] shows that the query has no
parameters. The where member contains the clauses that select entities. The
clause [?house <house>] binds ?house to each entity with the house tag.
The clause [schema {name string? unsealed [optional [maybe boolean?]]} ?house] checks
each house. Its name must be a string. Its unsealed field must be missing or
a boolean. A later step adds the unsealed tag to a house when its atomics
unseal. A house without this tag keeps its atomics sealed.
The project member {?house <name unsealed>} gives the name and
unsealed fields of each ?house as one result row. The schema clause also
gives the types of these fields to the SDK, so each generated row has the
fields Name string and Unsealed *bool. Unsealed is nil when the house
does not have the tag.
The export form
export names the definitions that the SDK makes available. The SDK generates
a method for each exported mutation and query. A definition that export does
not name has no SDK method.
The DUST database reference gives the full syntax of these forms.
Generate the SDK
Create seed/main.go with this program. It opens the database with the SDK plugin enabled and saves the files in one transaction. The plugin generates the SDK after the definitions commit.
package main
import (
"fmt"
"log"
"stardust"
)
func main() {
db, err := stardust.OpenConfig(stardust.Config{
Plugins: &stardust.Plugins{
Stdlib: true,
Database: &stardust.DatabaseSettings{Path: "dune.db"},
SDKs: &stardust.SDKSettings{
Go: &stardust.GoSDKSettings{Directory: "./sdk"},
},
},
})
if err != nil {
log.Fatal(err)
}
defer db.Close()
response, err := db.UpdateDefinitionsFromDir("./definitions")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Updated %d namespace(s); generated ./sdk\n", len(response.Namespaces))
}
Run go run ./seed from the module directory. It creates dune.db and the sdk directory.