Define a person as a struct, record, dataclass or map with name, role and age. This fragment uses the open database handle db. The map keys #_ada, #_bob and #_cy are temporary entity names that this patch creates.
The merge-patch value operation encodes those values into a temporary native document, commits it as one transaction, and closes the temporary document. Pass a document instead when you already have one; it is used directly, without a copy. A string value stays a string. Parse patch text before passing it to the document operation. C uses that document operation below.
Store Go structs and retain the commit result
type Person struct {
Name string `json:"name"`
Role string `json:"role"`
Age int `json:"age"`
}
people := map[string]Person{
"#_ada": {Name: "Ada", Role: "engineer", Age: 36},
"#_bob": {Name: "Bob", Role: "engineer", Age: 41},
"#_cy": {Name: "Cy", Role: "designer", Age: 29},
}
result, err := stardust.MergePatchValue(db, people, nil)
if err != nil {
return err
}{status committed
transaction 4
facts 9
committed_at 17928498230848613
ids {#_ada 1
#_bob 2
#_cy 3}}The commit record holds the transaction and the IDs of the new entities. Temporary names are scoped to one patch, not durable identifiers. See Language values and documents for the type mapping, and Queries and mutations for patches and transaction metadata such as #_tx.