英文:
how to get entity by key in google app engine using go language
问题
现在我使用Go语言在Datastore中添加了一些实体,我可以查询所有实体,但我想通过键获取一个实体,如何获取实体的键并按键查询,就像这样:select * from Blog where key=?
c := appengine.NewContext(r)
g := Blog{
Title: r.FormValue("title"),
Content: r.FormValue("content"),
}
_, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Blog", nil), &g)
英文:
now I add some entity in datastore using Go language,
I can query all entity, but I want get a entity by key,
how to get entity'key and query by key like this: select * from Blog where key=?
c := appengine.NewContext(r)
g := Blog{
Title: r.FormValue("title"),
Content: r.FormValue("content"),
}
_, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Blog", nil), &g)
Thanks
答案1
得分: 2
查看Go Runtime的Datastore文档:
var b Blog
err := datastore.Get(c, key, &b)
英文:
See the Datastore documentation for the Go Runtime:
var b Blog
err := datastore.Get(c, key, &b)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论