Google App Engine中的查询/数据存储出现问题-Go API

I'm playing with Google App Engine using the Go APIs and despite everything I've tried I can't get the Queries to return data that is in the datastore. I can see that Put() works as expected, and the entities are listable/accessible from inspection of the Admin Console available from dev_appserver.py

The struct I'm storing is defined this way:

type TweetData struct {
    Id int64 `datastore:",noindex" json:"id"`
    Text string `datastore:",noindex" json:"text"`
    Screen_name string `json:"screen_name"`
}

And my calls to query it are such:

func getDatastoreTweets(c appengine.Context, twitterUser string) []*TweetData {
    q := datastore.NewQuery("TweetData").Filter("Screen_name =", twitterUser).Order("-Id").Limit(10)

    var oldTweets []*TweetData
    if _, err := q.GetAll(c, &oldTweets); err != nil {
        fmt.Printf("Getall had non-nil error! %v
", err)
    }   

    return oldTweets
}

For this query, err is never non-nil, but always returns 0 results, even when the Console tells me there are many. I've tried it without the Filter call as well, after the guestbook example the SDK provides, to no avail.

In case it's an issue with keys (unlikely if I understand correctly, because I'm querying on a property), the call to Put is as follows:

// tweetData passed in via parameter...
key := datastore.NewIncompleteKey(c, "TweetData", nil)
_, err := datastore.Put(c, key, &tweetData)

Any help would be appreciated, thanks! ^_^

The query ask for ordering by Id desc, while the index field is un-indexed, you should either:

  • rewrite the TweetData annotation to index Id field:

Id int64 `json:"id"`

  • Remove the Order clause of your query:

q := datastore.NewQuery("TweetData").Filter("Screen_name =", twitterUser).Limit(10)