Class: Gcloud::Datastore::GqlQuery
- Inherits:
-
Object
- Object
- Gcloud::Datastore::GqlQuery
- Defined in:
- lib/gcloud/datastore/gql_query.rb
Overview
# GqlQuery
Represents a GQL query.
GQL is a SQL-like language for retrieving entities or keys from Datastore.
Instance Method Summary collapse
-
#allow_literals ⇒ Boolean
Whether the query may contain literal values.
-
#allow_literals=(new_allow_literals) ⇒ Object
Sets whether the query may contain literal values.
-
#initialize ⇒ GqlQuery
constructor
Returns a new GqlQuery instance.
-
#named_bindings ⇒ Hash
The named binding values for a query that contains named argument binding sites that start with ‘@`.
-
#named_bindings=(new_named_bindings) ⇒ Object
Sets named binding values for a query that contains named argument binding sites that start with ‘@`.
-
#positional_bindings ⇒ Array
The binding values for a query that contains numbered argument binding sites that start with ‘@`.
-
#positional_bindings=(new_positional_bindings) ⇒ Object
Sets the binding values for a query that contains numbered argument binding sites that start with ‘@`.
-
#query_string ⇒ String
The GQL query string for the query.
-
#query_string=(new_query_string) ⇒ Object
Sets the GQL query string for the query.
- #to_grpc ⇒ Object
Constructor Details
#initialize ⇒ GqlQuery
Returns a new GqlQuery instance.
43 44 45 |
# File 'lib/gcloud/datastore/gql_query.rb', line 43 def initialize @grpc = Google::Datastore::V1beta3::GqlQuery.new end |
Instance Method Details
#allow_literals ⇒ Boolean
Whether the query may contain literal values. When false, the query string must not contain any literals and instead must bind all values using #named_bindings= or #positional_bindings=.
89 90 91 |
# File 'lib/gcloud/datastore/gql_query.rb', line 89 def allow_literals @grpc.allow_literals end |
#allow_literals=(new_allow_literals) ⇒ Object
Sets whether the query may contain literal values. When false, the query string must not contain any literals and instead must bind all values using #named_bindings= or #positional_bindings=.
107 108 109 |
# File 'lib/gcloud/datastore/gql_query.rb', line 107 def allow_literals= new_allow_literals @grpc.allow_literals = new_allow_literals end |
#named_bindings ⇒ Hash
The named binding values for a query that contains named argument binding sites that start with ‘@`.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/gcloud/datastore/gql_query.rb', line 118 def named_bindings bindings = Hash[@grpc.named_bindings.map do |name, gql_query_param| if gql_query_param.cursor [name, Cursor.from_grpc(gql_query_param.cursor)] else [name, GRPCUtils.from_value(gql_query_param.value)] end end] bindings.freeze bindings end |
#named_bindings=(new_named_bindings) ⇒ Object
Sets named binding values for a query that contains named argument binding sites that start with ‘@`.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/gcloud/datastore/gql_query.rb', line 143 def named_bindings= new_named_bindings @grpc.named_bindings.clear new_named_bindings.map do |name, value| if value.is_a? Gcloud::Datastore::Cursor @grpc.named_bindings[name.to_s] = \ Google::Datastore::V1beta3::GqlQueryParameter.new( cursor: value.to_grpc) else @grpc.named_bindings[name.to_s] = \ Google::Datastore::V1beta3::GqlQueryParameter.new( value: GRPCUtils.to_value(value)) end end end |
#positional_bindings ⇒ Array
The binding values for a query that contains numbered argument binding sites that start with ‘@`.
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/gcloud/datastore/gql_query.rb', line 165 def positional_bindings bindings = @grpc.positional_bindings.map do |gql_query_param| if gql_query_param.cursor Cursor.from_grpc gql_query_param.cursor else GRPCUtils.from_value gql_query_param.value end end bindings.freeze bindings end |
#positional_bindings=(new_positional_bindings) ⇒ Object
Sets the binding values for a query that contains numbered argument binding sites that start with ‘@`.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/gcloud/datastore/gql_query.rb', line 190 def positional_bindings= new_positional_bindings @grpc.positional_bindings.clear new_positional_bindings.map do |value| if value.is_a? Gcloud::Datastore::Cursor @grpc.positional_bindings << \ Google::Datastore::V1beta3::GqlQueryParameter.new( cursor: value.to_grpc) else @grpc.positional_bindings << \ Google::Datastore::V1beta3::GqlQueryParameter.new( value: GRPCUtils.to_value(value)) end end end |
#query_string ⇒ String
The GQL query string for the query. The string may contain named or positional argument binding sites that start with ‘@`. Corresponding binding values should be set with #named_bindings= or #positional_bindings=.
55 56 57 58 59 |
# File 'lib/gcloud/datastore/gql_query.rb', line 55 def query_string gql = @grpc.query_string.dup gql.freeze gql end |
#query_string=(new_query_string) ⇒ Object
Sets the GQL query string for the query. The string may contain named or positional argument binding sites that start with ‘@`. Corresponding binding values should be set with #named_bindings= or #positional_bindings=.
See the [GQL Reference](cloud.google.com/datastore/docs/apis/gql/gql_reference).
78 79 80 |
# File 'lib/gcloud/datastore/gql_query.rb', line 78 def query_string= new_query_string @grpc.query_string = new_query_string.to_s end |
#to_grpc ⇒ Object
206 207 208 |
# File 'lib/gcloud/datastore/gql_query.rb', line 206 def to_grpc @grpc end |