2017-04-11 9 views
1
私はエンティティを取得するクエリを作成しようと

タグ=「赤」ORタグ私はそれが好きで行うことはできませんGoogleクラウド柔軟なクエリ

=「青」:方法はあり

colors = ["red", "yellow"] 
query.where("tag", "=", colors[0]).where("tag", "=", colors[1]) 

柔軟性のある「OR」フィルタでそれを作るのですか?

私も

query.query_string = "SELECT * FROM Item WHERE tag = @1 OR tag = @2" 

しかしdocumentationのような文字列のクエリを検討していたことは言う:私は「

=とOR演算子は、まだデータストア GQLで

答えて

0

!=とOR演算子は、Ruby Google Cloudの宝石ではサポートされていません。 OR演算子を模倣するには、ORDステートメントごとにCloud Datastoreにクエリを実行し、結果を連結します。 、次のコードに似ていますが、まさにこのコードが重複を含めることができないので:

datastore = Google::Cloud::Datastore.new 

red_query = Google::Cloud::Datastore::Query.new 
red_query.kind("messages").where("tags", "=", "red") 
items = datastore.run red_query 

yellow_query = Google::Cloud::Datastore::Query.new 
yellow_query.kind("messages").where("tags", "=", "yellow") 

items.concat datastore.run(yellow_query) 

items.each do |item| 
    puts "Tags: #{item['tags']}" 
end 

コード:

query.where("tag", "=", colors[0]).where("tag", "=", colors[1]) 

はOR演算として誤って解釈される可能性が、それはAND演算です。 Source

nshmuraによって指摘されているように、APIではAND演算子以外の演算子はサポートされていません。

関連する問題