App Engine Go中无用的查询

时间:2013-02-19 01:42:29

标签: google-app-engine google-cloud-datastore go

在Python中它是

q = db.Query()
q.ancestor(ancestor_key)

我试过了:

q := datastore.NewQuery("")
q.Ancestor(ancestor_key)

运行GetAll时出现错误“datastore:empty kind”

我也尝试过:

q := &datastore.Query{}
q.Ancestor(ancestor_key)

我收到错误“datastore:empty query kind”

提前感谢您对此事的任何帮助。

3 个答案:

答案 0 :(得分:2)

  

func NewQuery

     

func NewQuery(kind string)* Query

     

NewQuery为特定实体类创建新查询。那种必须   非空。

在您的代码中,

q := datastore.NewQuery("")

那种空虚。

答案 1 :(得分:1)

Rich Churcher的评论似乎是正确的,至少在这个时间点。

  

我认为Go中不支持Python无用的祖先查询。   那一刻,我以为你可以使用祖先键的种类()   方法,然后我又喝了一些咖啡,感觉很好。

答案 2 :(得分:0)

GetAll似乎无法运作,但您可以进行无聊的查询。

ctx := appengine.NewContext(r)
q := datastore.NewQuery("")
for it := q.Run(ctx); ; {
  key, err := t.Next(nil)
  if err == datastore.Done {
    break
  }
  if err != nil {
    break
  }
  fmt.Printf("%v\n", key)
}