google-app-enginegoogle-cloud-datastoregoogle-app-engine-golang

GetAll() in a cloud.google.com/go/datastore Transaction{}?


I need to run an equivalent of this, but in a transaction: db.GetAll(ctx, datastore.NewQuery("Items").Ancestor(pkey), &itemContainers)

But the Transaction{} type does not seem to have a GetAll() method. How can I get this done?


Solution

  • To use queries in transactions you should attach your transaction to the query. E.g.

    q = datastore.NewQuery("Items").Ancestor(pkey).Transaction(tx)
    db.Getall(ctx, q, &itemContainers)