Cloud Datastore Client - Class GqlQuery (1.23.0) Stay organized with collections Save and categorize content based on your preferences.
Reference documentation and code samples for the Cloud Datastore Client class GqlQuery.
Query Google Cloud Datastore usingGQL.
By default, parameters MUST be bound using named or positional bindings.Literals are disabled by default, and must be enabled by setting$options['allowLiterals'] totrue. As with any SQL dialect, usingparameter binding is highly recommended.
Idiomatic usage is viaGoogle\Cloud\Datastore\Query\Google\Cloud\Datastore\DatastoreClient::gqlQuery().
Example:
use Google\Cloud\Datastore\DatastoreClient;$datastore = new DatastoreClient();$query = $datastore->gqlQuery('SELECT * FROM Companies');$res = $datastore->runQuery($query);foreach ($res as $company) { echo $company['companyName'] . PHP_EOL;}// Literals must be provided as bound parameters by default:$query = $datastore->gqlQuery('SELECT * FROM Companies WHERE companyName = @companyName', [ 'bindings' => [ 'companyName' => 'Google' ]]);// Positional binding is also supported:$query = $datastore->gqlQuery('SELECT * FROM Companies WHERE companyName = @1 LIMIT 1', [ 'bindings' => [ 'Google' ]]);// While not recommended, you can use literals in your query string:$query = $datastore->gqlQuery('SELECT * FROM Companies WHERE companyName = \'Google\'', [ 'allowLiterals' => true]);// Using cursors as query bindings:$cursor = $datastore->cursor($cursorValue);$query = $datastore->gqlQuery('SELECT * FROM Companies OFFSET @offset', [ 'bindings' => [ 'offset' => $cursor ]]);Namespace
Google \ Cloud \ Datastore \ QueryMethods
__construct
| Parameters | |
|---|---|
| Name | Description |
entityMapper | Google\Cloud\Datastore\EntityMapperAn instance of EntityMapper |
query | stringThe GQL Query string. |
options | arrayConfiguration Options |
↳ allowLiterals | boolWhether literal values will be allowed in the query string. Parameter binding is strongly encouraged over literals.Defaults to |
↳ bindings | arrayAn array of values to bind to the query string. Queries using Named Bindings should provide a key/value set, while queries using Positional Bindings must provide a simple array. Applications with no need for multitenancy should not set this value. |
queryObject
Format the query for use in the API.
| Returns | |
|---|---|
| Type | Description |
array | |
queryKey
Return the query_type union field name.
| Returns | |
|---|---|
| Type | Description |
string | |
aggregation
canPaginate
Indicate that this type does not support automatic pagination.
| Returns | |
|---|---|
| Type | Description |
bool | |
start
Fulfill the interface, but cursors are handled inside the query string.
| Parameter | |
|---|---|
| Name | Description |
cursor | string |
| Returns | |
|---|---|
| Type | Description |
void | |
jsonSerialize
Define the json representation of the object.
| Returns | |
|---|---|
| Type | Description |
array | |
Constants
BINDING_NAMED
Value: 'namedBindings'BINDING_POSITIONAL
Value: 'positionalBindings'Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-01-24 UTC.