Reference documentation and code samples for the Firestore in Datastore mode API class Google::Cloud::Datastore::GqlQuery.
GqlQuery
Represents a GQL query.
GQL is a SQL-like language for retrieving entities or keys from
Datastore.
Inherits
Object
Example
require"google/cloud/datastore"datastore=Google::Cloud::Datastore.newgql_query=Google::Cloud::Datastore::GqlQuery.newgql_query.query_string="SELECT * FROM Task ORDER BY created ASC"tasks=datastore.rungql_query
Methods
#allow_literals
defallow_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=.
Returns
(Boolean) — true if the query may contain literal values
#allow_literals=
defallow_literals=(new_allow_literals)
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=.
Parameter
new_allow_literals (Boolean) — true if the query may contain
literal values
Example
require"google/cloud/datastore"gql_query=Google::Cloud::Datastore::GqlQuery.newgql_query.query_string="SELECT * FROM Task "\"WHERE completed = false AND priority = 4"gql_query.allow_literals=true
The binding values for a query that contains numbered argument binding
sites that start with @.
Returns
(Array) — a frozen array containing the query arguments in the
order of the numbered binding sites in the query string
#positional_bindings=
defpositional_bindings=(new_positional_bindings)
Sets the binding values for a query that contains numbered argument
binding sites that start with @.
Parameter
new_positional_bindings (Array) — query arguments in the order
of the numbered binding sites in the query string
Example
require"google/cloud/datastore"gql_query=Google::Cloud::Datastore::GqlQuery.newgql_query.query_string="SELECT * FROM Task"\"WHERE completed = @1 AND priority = @2"gql_query.positional_bindings=[false,4]
#query_string
defquery_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=.
Returns
(String) — a GQL statement
#query_string=
defquery_string=(new_query_string)
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=.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Firestore in Datastore mode API - Class Google::Cloud::Datastore::GqlQuery (v2.13.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.0 (latest)](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery)\n- [2.12.0](/ruby/docs/reference/google-cloud-datastore/2.12.0/Google-Cloud-Datastore-GqlQuery)\n- [2.11.0](/ruby/docs/reference/google-cloud-datastore/2.11.0/Google-Cloud-Datastore-GqlQuery)\n- [2.10.0](/ruby/docs/reference/google-cloud-datastore/2.10.0/Google-Cloud-Datastore-GqlQuery)\n- [2.9.0](/ruby/docs/reference/google-cloud-datastore/2.9.0/Google-Cloud-Datastore-GqlQuery)\n- [2.8.0](/ruby/docs/reference/google-cloud-datastore/2.8.0/Google-Cloud-Datastore-GqlQuery)\n- [2.7.1](/ruby/docs/reference/google-cloud-datastore/2.7.1/Google-Cloud-Datastore-GqlQuery)\n- [2.6.0](/ruby/docs/reference/google-cloud-datastore/2.6.0/Google-Cloud-Datastore-GqlQuery)\n- [2.5.0](/ruby/docs/reference/google-cloud-datastore/2.5.0/Google-Cloud-Datastore-GqlQuery)\n- [2.4.0](/ruby/docs/reference/google-cloud-datastore/2.4.0/Google-Cloud-Datastore-GqlQuery)\n- [2.3.1](/ruby/docs/reference/google-cloud-datastore/2.3.1/Google-Cloud-Datastore-GqlQuery)\n- [2.2.4](/ruby/docs/reference/google-cloud-datastore/2.2.4/Google-Cloud-Datastore-GqlQuery) \nReference documentation and code samples for the Firestore in Datastore mode API class Google::Cloud::Datastore::GqlQuery.\n\nGqlQuery\n--------\n\nRepresents a GQL query.\n\nGQL is a SQL-like language for retrieving entities or keys from\nDatastore. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\ngql_query = Google::Cloud::Datastore::GqlQuery.new\ngql_query.query_string = \"SELECT * FROM Task ORDER BY created ASC\"\ntasks = datastore.run gql_query\n```\n\nMethods\n-------\n\n### #allow_literals\n\n def allow_literals() -\u003e Boolean\n\nWhether the query may contain literal values. When false, the query\nstring must not contain any literals and instead must bind all values\nusing [#named_bindings=](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery#Google__Cloud__Datastore__GqlQuery_named_bindings__instance_ \"Google::Cloud::Datastore::GqlQuery#named_bindings= (method)\") or [#positional_bindings=](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery#Google__Cloud__Datastore__GqlQuery_positional_bindings__instance_ \"Google::Cloud::Datastore::GqlQuery#positional_bindings= (method)\"). \n**Returns**\n\n- (Boolean) --- `true` if the query may contain literal values\n\n### #allow_literals=\n\n def allow_literals=(new_allow_literals)\n\nSets whether the query may contain literal values. When false, the\nquery string must not contain any literals and instead must bind all\nvalues using [#named_bindings=](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery#Google__Cloud__Datastore__GqlQuery_named_bindings__instance_ \"Google::Cloud::Datastore::GqlQuery#named_bindings= (method)\") or [#positional_bindings=](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery#Google__Cloud__Datastore__GqlQuery_positional_bindings__instance_ \"Google::Cloud::Datastore::GqlQuery#positional_bindings= (method)\"). \n**Parameter**\n\n- **new_allow_literals** (Boolean) --- `true` if the query may contain literal values\n**Example** \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ngql_query = Google::Cloud::Datastore::GqlQuery.new\ngql_query.query_string = \"SELECT * FROM Task \" \\\n \"WHERE completed = false AND priority = 4\"\ngql_query.allow_literals = true\n```\n\n### #initialize\n\n def initialize() -\u003e GqlQuery\n\nReturns a new GqlQuery instance. \n**Returns**\n\n- ([GqlQuery](./Google-Cloud-Datastore-GqlQuery)) --- a new instance of GqlQuery\n**Example** \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ngql_query = Google::Cloud::Datastore::GqlQuery.new\n```\n\n### #named_bindings\n\n def named_bindings() -\u003e Hash\n\nThe named binding values for a query that contains named argument\nbinding sites that start with `@`. \n**Returns**\n\n- (Hash) --- a frozen hash that maps the binding site names in the query string to valid GQL arguments\n\n### #named_bindings=\n\n def named_bindings=(new_named_bindings)\n\nSets named binding values for a query that contains named argument\nbinding sites that start with `@`. \n**Parameter**\n\n- **new_named_bindings** (Hash) --- a hash that maps the binding site names in the query string to valid GQL arguments\n**Example** \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ngql_query = Google::Cloud::Datastore::GqlQuery.new\ngql_query.query_string = \"SELECT * FROM Task \" \\\n \"WHERE done = @done \" \\\n \"AND priority = @priority\"\ngql_query.named_bindings = {done: false, priority: 4}\n```\n\n### #positional_bindings\n\n def positional_bindings() -\u003e Array\n\nThe binding values for a query that contains numbered argument binding\nsites that start with `@`. \n**Returns**\n\n- (Array) --- a frozen array containing the query arguments in the order of the numbered binding sites in the query string\n\n### #positional_bindings=\n\n def positional_bindings=(new_positional_bindings)\n\nSets the binding values for a query that contains numbered argument\nbinding sites that start with `@`. \n**Parameter**\n\n- **new_positional_bindings** (Array) --- query arguments in the order of the numbered binding sites in the query string\n**Example** \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ngql_query = Google::Cloud::Datastore::GqlQuery.new\ngql_query.query_string = \"SELECT * FROM Task\" \\\n \"WHERE completed = @1 AND priority = @2\"\ngql_query.positional_bindings = [false, 4]\n```\n\n### #query_string\n\n def query_string() -\u003e String\n\nThe GQL query string for the query. The string may contain named or\npositional argument binding sites that start with `@`. Corresponding\nbinding values should be set with [#named_bindings=](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery#Google__Cloud__Datastore__GqlQuery_named_bindings__instance_ \"Google::Cloud::Datastore::GqlQuery#named_bindings= (method)\") or\n[#positional_bindings=](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery#Google__Cloud__Datastore__GqlQuery_positional_bindings__instance_ \"Google::Cloud::Datastore::GqlQuery#positional_bindings= (method)\"). \n**Returns**\n\n- (String) --- a GQL statement\n\n### #query_string=\n\n def query_string=(new_query_string)\n\nSets the GQL query string for the query. The string may contain named\nor positional argument binding sites that start with `@`.\nCorresponding binding values should be set with [#named_bindings=](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery#Google__Cloud__Datastore__GqlQuery_named_bindings__instance_ \"Google::Cloud::Datastore::GqlQuery#named_bindings= (method)\") or\n[#positional_bindings=](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-GqlQuery#Google__Cloud__Datastore__GqlQuery_positional_bindings__instance_ \"Google::Cloud::Datastore::GqlQuery#positional_bindings= (method)\").\n\n\n\u003cbr /\u003e\n\nSee the [GQL\nReference](https://cloud.google.com/datastore/docs/apis/gql/gql_reference). \n**Parameter**\n\n- **new_query_string** (String) --- a valid GQL statement\n**Example** \n\n```ruby\ngql_query = Google::Cloud::Datastore::GqlQuery.new\ngql_query.query_string = \"SELECT * FROM Task \" \\\n \"WHERE done = @done \" \\\n \"AND priority = @priority\"\ngql_query.named_bindings = {done: false, priority: 4}\n```"]]