Class: Google::Cloud::Datastore::GqlQuery
- Inherits:
-
Object
- Object
- Google::Cloud::Datastore::GqlQuery
- Defined in:
- lib/google/cloud/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.
Constructor Details
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=.
98 99 100 |
# File 'lib/google/cloud/datastore/gql_query.rb', line 98 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=.
118 119 120 |
# File 'lib/google/cloud/datastore/gql_query.rb', line 118 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 @
.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/google/cloud/datastore/gql_query.rb', line 129 def named_bindings bindings = Hash[@grpc.named_bindings.map do |name, gql_query_param| if gql_query_param.parameter_type == :cursor [name, Cursor.from_grpc(gql_query_param.cursor)] else [name, Core::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 @
.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/google/cloud/datastore/gql_query.rb', line 157 def named_bindings= new_named_bindings @grpc.named_bindings.clear new_named_bindings.map do |name, value| if value.is_a? Google::Cloud::Datastore::Cursor @grpc.named_bindings[name.to_s] = \ Google::Datastore::V1::GqlQueryParameter.new( cursor: value.to_grpc) else @grpc.named_bindings[name.to_s] = \ Google::Datastore::V1::GqlQueryParameter.new( value: Core::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 @
.
179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/google/cloud/datastore/gql_query.rb', line 179 def positional_bindings bindings = @grpc.positional_bindings.map do |gql_query_param| if gql_query_param.parameter_type == :cursor Cursor.from_grpc gql_query_param.cursor else Core::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 @
.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/google/cloud/datastore/gql_query.rb', line 206 def positional_bindings= new_positional_bindings @grpc.positional_bindings.clear new_positional_bindings.map do |value| if value.is_a? Google::Cloud::Datastore::Cursor @grpc.positional_bindings << \ Google::Datastore::V1::GqlQueryParameter.new( cursor: value.to_grpc) else @grpc.positional_bindings << \ Google::Datastore::V1::GqlQueryParameter.new( value: Core::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=.
63 64 65 66 67 |
# File 'lib/google/cloud/datastore/gql_query.rb', line 63 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.
87 88 89 |
# File 'lib/google/cloud/datastore/gql_query.rb', line 87 def query_string= new_query_string @grpc.query_string = new_query_string.to_s end |