Bulk loading structs from a path query



I’m curious what the idiomatic way to load structs is after obtaining an iterator for a path query. E.g., suppose I have the path

p := cayley.StartPath(store, quad.IRI("organization:some-org")).
    Has(quad.IRI("rdf:type"), quad.IRI("foaf:topic"))

what is the optimal/idomatic way to load Topic{} structs once a path such as this has been constructed? One way to load them might be to iterate over the results and fetch each IRI one by one using LoadTo(). But is there a way to bulk load them?


Getting a little closer, I think the way to bulk load structs might be something like this:

it, _ := p.BuildIterator().Optimize()
it, _ = store.OptimizeIterator(it)
ctx := context.TODO()

var values []quad.Value
for it.Next(ctx) {
  values = append(values, store.NameOf(it.Result()))

var topics []Topic
err := schema.Global().LoadTo(ctx, store, &topics, values...)

But perhaps there’s an even more concise way?


Hi @emwalker,

Sure, you can use one of the methods like LoadPathTo or LoadIteratorTo instead of iterating and resolving values. The second function is assumed to be more low-level and expects you to call reflect.ValueOf on your object first.