I am writing a go application in app engine that connects and returns some info from datastore entities. I'm having an issue where client.Get is working with a predefined struct but client.GetAll is throwing a type mismatch (or vice versa).
I am using the following struct with both:
type myStruct struct {
ID int64
Field1 string
Field2 string
Release_Date time.Time
}
This works when Release_Date is defined as time.Time (fails if int):
k := db.datastoreKey(id)
myStruct := &myStruct{}
if err := db.client.Get(ctx, k, myStruct ); err != nil {
return nil, fmt.Errorf("datastore: %v", err)
}
func (db *datastoreDB) datastoreKey(id int64) *datastore.Key {
return datastore.IDKey("myEntityType", id, nil)
}
This fails when Release_Date is defined as time.Time (works if int):
var myStructs []*myStruct
q := datastore.NewQuery("myEntityType").
Project("field1", "field2", "release_date").
Order("field1")
keys, err := db.client.GetAll(ctx, q, &myStructs)
if err != nil {
return nil, fmt.Errorf("datastore: %v", err)
}
The error:
datastore: cannot load field "release_date" into a "myStruct": type mismatch: int versus time.Time
(or vice versa when I swap the Release_Date definition).
Any ideas what is wrong or is this a bug?
Additional info:
I've looked at the entity dashboard and there it lists the data type as Data/Time and when I retrieve the entity with Get it loads fine into the struct and I can use the object in my code.
I have no idea why this isn't working.
GetAll, it fails, since it will find at least one that doesn't match. - davek) in theGetexample, so we don't know if that's using the same"myEntityType"as theGetAllexample. One way or another, though, we know from your error messages that you've stored some entities'Release_Dateasintand some astime.Time. - Darshan Rivka WhittleNewQuery,Project, orOrderwith lower-case parameters, since they only work with exported types and fields. I'm not sure if the datastore package just treats them case-insensitively (since these are just string parameters referring to things you've already stored, that's entirely possible), but it stands at to me as unusual, and incongruous. - Darshan Rivka Whittlek. I also nuked all entries in my datastore and added a single entry (fun fact, it means you have to rebuild the indexes) triple-checking the data types. The parameters you refer to are the named fields in my datastore so they should match case, no? - tmwoods