我在Google Cloud Datastore中使用了多个名称空间
运行时:
require "google/cloud/datastore"
project_id = "PROJECT_ID"
datastore = Google::Cloud::Datastore.new project: project_id
...
query = Google::Cloud::Datastore::Query.new
query.kind "Task"
tasks = datastore.run query
它只检索来自'默认'的实体。命名空间
例如,在Python中,您可以通过以下方式定义命名空间:
dataclient = datastore.Client("PROJECT_ID", "NAMESPACE")
但我无法通过Ruby找到办法。我也没有找到任何有用的资料。
答案 0 :(得分:1)
我已经向Google询问了这个问题,他们给我发了一个例子:
# Datastore service client
datastore = Google::Cloud::Datastore.new
# Create a new entry with a namespace
entry = datastore.entity "kind", namespace: "test-namespace" do |entry|
entry["name"] = "YOURNAME"
end
# Save in datastore
datastore.save entry
# Query a namespaced entry
query = Google::Cloud::Datastore::Query.new
query.kind "kind"
datastore.run query, namespace: "test-namespace"