I'm currently working on golang http-based handler running on Google App Engine.
As part of this, I'm trying to pull back all the values I'm interested in via a Projection query looking at a number of fields in a given kind, with the intention of storing each entity load in a struct that mirrors the field types.
This is my query:
source := datastore.NewQuery("CacheEntry").Project("Campaign", "Creative", "Impressions", "Operator", "Publisher", "Slot").Limit(50)
Unfortunately, all I get back from this is empty strings (worse, returning empty strings does not throw an error of any kind so I've only just worked out that it's doing this).
Google's documentation and error reporting is pretty bad when it comes to Datastore so it hasn't been much help. I can see the populated fields on my Datastore viewer in the Google Cloud Console - some fields are actually empty but I should be returning some data at least.
I'm running it in a for loop with the appropriate pointers setup:
for t := source.Run(ctx); ; {
_, err := t.Next(&x)
log.Println(count)
if err == datastore.Done {
log.Println("failed on Datastore:done, count
")
log.Println(count)
break
}
if err != nil {
log.Println("failed on
")
log.Println(count)
http.Error(w, err.Error(), http.StatusInternalServerError)
break
}
// fmt.Fprint(w, x.Campaign)
if &x != nil {
fmt.Fprintln(w, "Strings:
")
fmt.Fprintln(w, x.Operator)
if x.Operator == "" {
fmt.Fprintln(w, "Campaign string is empty")
}
}
count = count + 1
'X' being:
type Row struct {
Campaign string
Creative string
Impressions int
Operator string
Publisher string
Slot string
}
Any ideas where I'm going wrong?
Figured it out, turns out a number of issues were happening in the background:
.Limit(50)
was being reached ... in that case, the query was running, but I was interpreting the empty string returns as errors when in fact they were correct, just not from the part of the dataset I'd expected - adding Filters for "<property> >", ""
fixed itDatastore sorely needs better feedback measures than the ones it has. Compared to a lot of similar dbs I've worked with, it's needlessly minimal in it's feedback.