google-app-engine - 通过id获取实体

标签 google-app-engine go

我正在为我的路线使用 gorilla 多路复用器并传递一个 id。

如何使用该 ID 从数据存储中获取实体。

param := mux.Vars(r)
c := appengine.NewContext(r)
item := []Item{}
pr, err := datastore.NewQuery("Item").Filter("ID = ", param["id"]).GetAll(c, &item)

我被卡住了,我尝试使用过滤器但它不起作用。

接下来我要做什么?

最佳答案

有了id就不用查询了。一种更快、更便宜的方法是创建一个键并直接从数据存储中检索该实体。

https://cloud.google.com/appengine/docs/go/datastore/entities#Go_Retrieving_an_entity

关于google-app-engine - 通过id获取实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26556788/

相关文章:

python - 使用 app.yaml 在 GAE 中安全地存储环境变量

java.lang.ClassNotFoundException : org. 代码豪斯.jackson.map.JsonSerializableWithType

go - 按字段内容过滤包含字符串

json - 在 golang 中持久化嵌套结构

mongodb - 模拟官方 MongoDb 驱动程序

python - 解析来自重定向 URL 的信息

Python App Engine SDK 仅加载默认模块

Java 11 标准环境与 ApiProxy 不兼容?

algorithm - D. B. Johnson 的 "elementary circuits"算法应该产生不同的结果吗?

google-app-engine - KeysOnly 函数不返回键