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.

TRON963 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0046C 236C6F63616Ctxt "#local"
00BDC 61746F6D696373 2D666F756E64txt "atomics-found"
0190F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
0236C 236C6F63616Ctxt "#local"
02A4C 6E616D65txt "name"
02F0F 0A 23000000 2A00 0000map leaf, size 10: @23 → @2A
0390E 0D 00 0100 010000 00 2F000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @2F
0466C 236C6F63616Ctxt "#local"
04D7C 737472696E673Ftxt "string?"
0550F 0A 46000000 4D00 0000map leaf, size 10: @46 → @4D
05F4C 6E616D65txt "name"
0640F 0A 5F000000 5500 0000map leaf, size 10: @5F → @55
06E6C 236C6F63616Ctxt "#local"
0754C 6E616D65txt "name"
07A0F 0A 6E000000 7500 0000map leaf, size 10: @6E → @75
0845C 686F757365txt "house"
08A09bit true
08B0F 0A 84000000 8A00 0000map leaf, size 10: @84 → @8A
0954C 6E616D65txt "name"
09A0F 0A 95000000 7A00 0000map leaf, size 10: @95 → @7A
0A407 0E 08800000 8B00 0000 9A000000map branch, size 14, depth 0 (root), slots 3, 15: @8B → @9A
0B26C 5F686F757365txt "_house"
0B90F 0A B2000000 A400 0000map leaf, size 10: @B2 → @A4
0C35C 7061746368txt "patch"
0C90F 0A C3000000 B900 0000map leaf, size 10: @C3 → @B9
0D36C 736368656D61txt "schema"
0DA0F 0A D3000000 6400 0000map leaf, size 10: @D3 → @64
0E407 0E 01040000 C900 0000 DA000000map branch, size 14, depth 1, slots 0, 10: @C9 → @DA
0F207 0A 80000000 E400 0000map branch, size 10, depth 0 (root), slots 7: @E4
0FCBC 6465666D757461 74696F6Etxt "defmutation"
1080E 19 00 0F00 040000 00 FC000000 190000 00 39000000 F20000 00array leaf, size 25, shift 0, bitmap 000F, count 4 (root): @FC → @19 → @39 → @F2
Show all 100 nodes
Offset (hex)Bytes (hex)Meaning
1217C 23696E766F6B65txt "#invoke"
1290F 0A 21010000 0801 0000map leaf, size 10: @121 → @108
1336C 236C6F63616Ctxt "#local"
13A6C 686F75736573txt "houses"
1410F 0A 33010000 3A01 0000map leaf, size 10: @133 → @13A
14B0E 09 00 0000 000000 00array leaf, size 9, shift 0, bitmap 0000, count 0 (root)
1546C 236C6F63616Ctxt "#local"
15B6C 3F686F757365txt "?house"
1620F 0A 54010000 5B01 0000map leaf, size 10: @154 → @15B
16C5C 686F757365txt "house"
17209bit true
1730F 0A 6C010000 7201 0000map leaf, size 10: @16C → @172
17D0E 11 00 0300 020000 00 62010000 730100 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @162 → @173
18E6C 236C6F63616Ctxt "#local"
1956C 736368656D61txt "schema"
19C0F 0A 8E010000 9501 0000map leaf, size 10: @18E → @195
1A66C 236C6F63616Ctxt "#local"
1AD7C 737472696E673Ftxt "string?"
1B50F 0A A6010000 AD01 0000map leaf, size 10: @1A6 → @1AD
1BF6C 236C6F63616Ctxt "#local"
1C68C 6F7074696F6E61 6Ctxt "optional"
1CF0F 0A BF010000 C601 0000map leaf, size 10: @1BF → @1C6
1D96C 236C6F63616Ctxt "#local"
1E05C 6D61796265txt "maybe"
1E60F 0A D9010000 E001 0000map leaf, size 10: @1D9 → @1E0
1F06C 236C6F63616Ctxt "#local"
1F78C 626F6F6C65616E 3Ftxt "boolean?"
2000F 0A F0010000 F701 0000map leaf, size 10: @1F0 → @1F7
20A0E 11 00 0300 020000 00 E6010000 000200 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @1E6 → @200
21B0E 11 00 0300 020000 00 CF010000 0A0200 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @1CF → @20A
22C8C 756E7365616C65 64txt "unsealed"
2350F 0A 2C020000 1B02 0000map leaf, size 10: @22C → @21B
23F4C 6E616D65txt "name"
2440F 0A 3F020000 B501 0000map leaf, size 10: @23F → @1B5
24E07 0E 10800000 3502 0000 44020000map branch, size 14, depth 0 (root), slots 4, 15: @235 → @244
25C6C 236C6F63616Ctxt "#local"
2636C 3F686F757365txt "?house"
26A0F 0A 5C020000 6302 0000map leaf, size 10: @25C → @263
2740E 15 00 0700 030000 00 9C010000 4E0200 00 6A020000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @19C → @24E → @26A
2890E 11 00 0300 020000 00 7D010000 740200 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @17D → @274
29A8C 756E7365616C65 64txt "unsealed"
2A309bit true
2A40F 0A 9A020000 A302 0000map leaf, size 10: @29A → @2A3
2AE4C 6E616D65txt "name"
2B309bit true
2B40F 0A AE020000 B302 0000map leaf, size 10: @2AE → @2B3
2BE07 0E 10800000 A402 0000 B4020000map branch, size 14, depth 0 (root), slots 4, 15: @2A4 → @2B4
2CC6C 3F686F757365txt "?house"
2D30F 0A CC020000 BE02 0000map leaf, size 10: @2CC → @2BE
2DD5C 7768657265txt "where"
2E30F 0A DD020000 8902 0000map leaf, size 10: @2DD → @289
2ED7C 70726F6A656374txt "project"
2F50F 0A ED020000 D302 0000map leaf, size 10: @2ED → @2D3
2FF07 0E 02040000 E302 0000 F5020000map branch, size 14, depth 0 (root), slots 1, 10: @2E3 → @2F5
30D8C 64656671756572 79txt "defquery"
3160E 19 00 0F00 040000 00 0D030000 410100 00 4B010000 FF0200 00array leaf, size 25, shift 0, bitmap 000F, count 4 (root): @30D → @141 → @14B → @2FF
32F7C 23696E766F6B65txt "#invoke"
3370F 0A 2F030000 1603 0000map leaf, size 10: @32F → @316
3416C 236C6F63616Ctxt "#local"
348DC 61746F6D696373 2D666F756E64txt "atomics-found"
3560F 0A 41030000 4803 0000map leaf, size 10: @341 → @348
3606C 236C6F63616Ctxt "#local"
3676C 686F75736573txt "houses"
36E0F 0A 60030000 6703 0000map leaf, size 10: @360 → @367
3786C 6578706F7274txt "export"
37F0E 15 00 0700 030000 00 78030000 560300 00 6E030000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @378 → @356 → @36E
3947C 23696E766F6B65txt "#invoke"
39C0F 0A 94030000 7F03 0000map leaf, size 10: @394 → @37F
3A60E 15 00 0700 030000 00 29010000 370300 00 9C030000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @129 → @337 → @39C
Offset (hex)Bytes (hex)Meaning

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.

go565 B
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.