在App Engine Go中的无情查询

huangapple go评论87阅读模式
英文:

Kindless Queries in App Engine 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)

当运行GetAll时,我得到了错误“datastore: empty query kind”。

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

英文:

In Python it's

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

I tried:

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

I get the error "datastore: empty kind" when running GetAll

I also tried:

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

I get the error "datastore: empty query kind"

Thanks in advance for any help with this matter.

答案1

得分: 2

> func NewQuery
>
> func NewQuery(kind string) *Query
>
> NewQuery创建一个特定实体类型的新查询。实体类型必须非空。

在你的代码中,

q := datastore.NewQuery("")

实体类型是空的。

英文:

> func NewQuery
>
> func NewQuery(kind string) *Query
>
> NewQuery creates a new Query for a specific entity kind. The kind must
> be non-empty.

In your code,

q := datastore.NewQuery("")

the kind is empty.

答案2

得分: 1

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

我不认为Go支持Python中的祖先查询。
有一瞬间我以为你可以使用祖先键的Kind()方法,然后我喝了更多咖啡,恢复了理智。

英文:

Rich Churcher's comment seems to be right, at least at this point in time.
> I don't think the Python kindless ancestor query is supported in Go.
> For a moment there I thought you could use the ancestor key's Kind()
> method, then I had some more coffee and came to my senses.

答案3

得分: 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)
}
英文:

GetAll doesn't seem to work, but you can do kindless queries.

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)
}

huangapple
  • 本文由 发表于 2013年2月19日 09:42:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/14948440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定