2017-04-11 3 views
1
내가 가진 개체를 검색하는 쿼리를 만들려고

태그 = "빨간색"또는 태그 내가 좋아 할 수없는Google 클라우드 유연한 쿼리

= "파란색"방법이 있나요

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

유연한 'OR'필터로 만들 수 있습니까? !

= 및 OR 연산자가 아직 데이터 저장소 GQL 지원하지 않습니다

답변

0

! = 및 OR 연산자는 Ruby Google Cloud 보석에서 지원되지 않습니다. OR 연산자를 모방 한 ORD 문당 Cloud Datastore를 쿼리하고 결과를 연결하여 OR 연산자를 모방 할 수 있습니다. 다음 코드 유사하지만, 정확히이 코드가 포함 할 수 있기 때문에 중복 :

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 연산으로 잘못 해석 될 수 있지만, 그것은 연산을합니다. Source.

nshmura가 지적한 것처럼 API는 AND 연산자 이외의 연산자를 지원하지 않습니다.

0

나 ':

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

하지만 documentation 같은

심지어 고려하고 문자열 쿼리는 말한다 ruby clientGRPC API 또는 REST API을 사용하지만 각각의 API는 t OR 작업을 지원합니다. Operator of REST API

Operator of GRPC API

    • 그래서 나는 OR 작업이 불가능하다 생각합니다.

  • 관련 문제