The birthday mutation selects Ada and adds one to her age. It then queries the age to verify the committed change. This fragment assumes an open database named db containing the people fixture. In your application, run it before the lifecycle sequence releases its database; adapt db to that sequence's handle name. If you already ran the complete sequence and closed its handles, reopen the same database rather than reseeding it. The independent verification harness seeds a fresh database with that same fixture.
Parse birthdayText with the selected format, build a mutation against the database, and run it. Keep external effects after a successful commit. Then release the mutation and query result handles as shown.
Give Ada her birthday and read her age
birthdayText holds this document:
query {find [?e]
where [[?e name Ada]]}
patch {?e {age 37}}
queryText holds this document:
find [?age]
where [[?e name Ada]
[?e age ?age]]
birthday, err := stardust.Parse(birthdayText, stardust.DUST)
if err != nil {
return err
}
defer birthday.Close()
mutation, err := db.Mutation(birthday)
if err != nil {
return err
}
defer mutation.Close()
if _, err := mutation.Run(nil, stardust.RunOptions{}, nil); err != nil {
return err
}
definition, err := stardust.Parse(queryText, stardust.DUST)
if err != nil {
return err
}
defer definition.Close()
query, err := db.Query(definition)
if err != nil {
return err
}
defer query.Close()
rows, err := query.Run(nil, stardust.RunOptions{}, nil)
if err != nil {
return err
}
defer rows.Close()
result, err := rows.AllPages()
if err != nil {
return err
}
defer result.Close()[{age 37}]The captured age is 37. The harness setup is not an instruction to create the preceding people twice. See Queries and mutations for commit results and failures.