PHP Class Google\Cloud\Datastore\Query\GqlQuery

By default, parameters MUST be bound using named or positional bindings. Literals are disabled by default, and must be enabled by setting $options['allowLiterals'] to true. As with any SQL-style language, using parameter binding is highly recommended. Idiomatic usage is via {@see \Google\Cloud\Datastore\DatastoreClient::gqlQuery()}. Example: use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $datastore = $cloud->datastore(); $query = $datastore->gqlQuery('SELECT * FROM Companies WHERE companyName = @companyName', [ 'bindings' => [ 'companyName' => 'Google' ] ]); $res = $datastore->runQuery($query); foreach ($res as $company) { echo $company['companyName']; // Google } Positional binding is also supported $query = $datastore->gqlQuery('SELECT * FROM Companies WHERE companyName = @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 ]);
See also: https://cloud.google.com/datastore/docs/apis/gql/gql_reference GQL Reference
Inheritance: implements Google\Cloud\Datastore\Query\QueryInterface, use trait Google\Cloud\ArrayTrait, use trait Google\Cloud\Datastore\DatastoreTrait
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php Class Usage Examples

Public Methods

Method Description
__construct ( EntityMapper $entityMapper, string $query, array $options = [] )
canPaginate ( ) : boolean Indicate that this type does not support automatic pagination.
jsonSerialize ( ) : array Define the json respresentation of the object.
queryKey ( ) : string Return the query_type union field name.
queryObject ( ) : array Format the query for use in the API
start ( string $cursor ) : void Fulfill the interface, but cursors are handled inside the query string.

Private Methods

Method Description
determineBindingType ( array $options ) : string Determine whether the query should use named or positional bindings.
mapBindings ( string $bindingType, array $bindings ) : array Format bound values for the API

Method Details

__construct() public method

public __construct ( EntityMapper $entityMapper, string $query, array $options = [] )
$entityMapper Google\Cloud\Datastore\EntityMapper An instance of EntityMapper
$query string The GQL Query string.
$options array [optional] { Configuration Options @type bool $allowLiterals Whether literal values will be allowed in the query string. Parameter binding is strongly encouraged over literals. **Defaults to** `false`. @type array $bindings An 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. }

canPaginate() public method

Indicate that this type does not support automatic pagination.
public canPaginate ( ) : boolean
return boolean

jsonSerialize() public method

Define the json respresentation of the object.
public jsonSerialize ( ) : array
return array

queryKey() public method

Return the query_type union field name.
public queryKey ( ) : string
return string

queryObject() public method

This method is used internally to run queries and is not intended for use outside the internal library API
public queryObject ( ) : array
return array

start() public method

Fulfill the interface, but cursors are handled inside the query string.
public start ( string $cursor ) : void
$cursor string
return void