2

命名空間我在谷歌雲存儲如何定義查詢

使用多個命名空間當運行:

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

但我找不到辦法做我t由Ruby。我還沒有發現任何有用的資源。

+0

貌似有從一年前這一主題的PR,我認爲他們已經增加了。 https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/404 – bkunzi01

+0

是的。謝謝! –

回答

1

我問過谷歌在這一點,他們已經給我發了一個例子:

# 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"