queryText in the sequence selects each person's name and orders the result by name. Parse it, build a query against the open database, run it, and read the next result page.
The example reads one page. To read the remaining pages as needed, use the lazy Pages iterator; C calls next until a page is empty. AllPages eagerly reads every remaining page into one array of rows before returning. Its memory use grows with the remaining result. Release the rows and query when finished, because open rows hold a store read transaction. Serialize a page in your selected format at your output boundary. Reserve typed reads and builders for the advanced Documents and Building reference.
Store people and query their names
seedText holds this document:
#_ada {name Ada
role engineer
age 36}
#_bob {name Bob
role engineer
age 41
mentor {#link #_ada}}
#_cy {name Cy
role designer
age 29}
#_tx {author smoke
reason seed}
queryText holds this document:
find [?name]
where [[?e name ?name]]
orderBy [?name]
opened, err := stardust.Open(databasePath, stardust.Options{})
if err != nil {
return err
}
defer opened.Close()
seed, err := stardust.Parse(seedText, stardust.DUST)
if err != nil {
return err
}
defer seed.Close()
if _, err := opened.MergePatch(seed, nil); err != nil {
return err
}
definition, err := stardust.Parse(queryText, stardust.DUST)
if err != nil {
return err
}
defer definition.Close()
query, err := opened.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.Next()
if err != nil {
return err
}
defer result.Close()[{name Ada} {name Bob} {name Cy}]The captured names are Ada, Bob and Cy in order. Query definitions are documents, not generated SDK methods. See Queries and mutations for parameters, paging and run options.