Trouble with Query.GetAll() using PropertyList to hold the entities

422 views
Skip to first unread message

matryer

unread,
Jan 19, 2012, 1:38:54 PM1/19/12
to golang-nuts
I am trying to work with entities WITHOUT predefining the structs, and
instead of using a map (which is now deprecated) I am using
datastore.PropertyList (and datastore.Property items inside).

Despite successfully saving items (and being able to load them one at
a time if I know the key), I am unable to use Query.GetAll() to load a
set of them.

For example:

---
// save an entity
var plist datastore.PropertyList = make(datastore.PropertyList, 3)
plist = append(plist, datastore.Property { "name", "Mat", false,
false })
plist = append(plist, datastore.Property { "age", "29", false,
false })
plist = append(plist, datastore.Property { "location", "London",
false, false })
key := datastore.NewIncompleteKey(context, "Record", nil)
datastore.Put(context, key, &plist)

// load them all
query := datastore.NewQuery("Record")
plists := make(datastore.PropertyList, 0, 10)
keys, err := query.GetAll(context, &plists)
---

I get the following error: "datastore: cannot load field "age" into a
"datastore.Property": no such struct field"

It seems that it doesn't complain about `Name` because that happens to
be a valid property of datastore.Property, so how do I get it to load
the items as intended, with each item in `plists` itself being a
datastore.PropertyList instead of datastore.Property?

I asked this question at SO too:
http://stackoverflow.com/questions/8931134/putting-many-propertylists-into-google-app-engine-datastore-in-go-and-loading

David Symonds

unread,
Jan 19, 2012, 4:37:51 PM1/19/12
to matryer, golang-nuts
On Fri, Jan 20, 2012 at 5:38 AM, matryer <mat...@mac.com> wrote:

> plists := make(datastore.PropertyList, 0, 10)
> keys, err := query.GetAll(context, &plists)

According to the docs on GetAll, "The dst must be a pointer to a slice
of structs, struct pointers, or Maps.". GetAll does not support
PropertyList (et al) yet.


Dave.

Reply all
Reply to author
Forward
0 new messages