GAE过滤器实体键(Golang)

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

GAE filter entity key (Golang)

问题

我想使用类似的方式来获取实体键:

datastore.NewQuery("Article").Filter("ID =", id)

怎么做呢?

对不起,我的英语不好。谢谢!

英文:

I want to use look like

datastore.NewQuery("Article").Filter("ID =", id)

to get entity key.

How do this?

Sorry for my poor English. Thanks!

答案1

得分: 11

这些解决方案怎么样,这种方式不需要查询,也不需要迭代器,更直接地解决问题。

var article Article
k := datastore.NewKey(c, "Article", "", usrr.User, nil)
q := datastore.Get(c,k,&article)

你觉得怎么样?

英文:

What about these solution, these way you dont need a query, neither an iterator is more direct way of solving the problem.

var article Article
k := datastore.NewKey(c, "Article", "", usrr.User, nil)
q := datastore.Get(c,k,&article)

What did you think?

答案2

得分: 2

k := datastore.NewKey(c, "Activity", "", id, nil)
q := datastore.NewQuery("Article").Filter("key =", k)

其中 c 是你的 appengine.Context

英文:

I never tried Go but I'll give it a shot:

k := datastore.NewKey(c, "Activity", "", id, nil)
q := datastore.NewQuery("Article").Filter("__key__ =", k)

Where c is your appengine.Context

huangapple
  • 本文由 发表于 2012年9月30日 14:14:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/12659126.html
匿名

发表评论

匿名网友

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

确定