PHP Class Google\Cloud\Datastore\Query\Query

Queries can be created either by using the builder pattern, or by providing a Query when creating this object. Example: use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $datastore = $cloud->datastore(); $query = $datastore->query(); $query->kind('Person'); $query->filter('firstName', 'Bob'); $result = $datastore->runQuery($query); Queries can also be constructed using a Query Object: $query = $datastore->query([ 'query' => [ 'kind' => [ [ 'name' => 'People' ] ], 'filter' => [ 'propertyFilter' => [ 'op' => 'EQUAL', 'property' => [ 'name' => 'firstName' ], 'value' => [ 'stringValue': 'Bob' ] ] ] ] ]); $result = $datastore->runQuery($query);
See also: https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#query Query Object Reference
See also: https://cloud.google.com/datastore/docs/concepts/queries Datastore Queries
Inheritance: implements Google\Cloud\Datastore\Query\QueryInterface, use trait Google\Cloud\Datastore\DatastoreTrait
Afficher le fichier Open project: GoogleCloudPlatform/gcloud-php Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( EntityMapper $entityMapper, array $query = [] )
canPaginate ( ) : boolean Indicate that this type does support automatic pagination.
distinctOn ( array | string $property ) : Query The properties to make distinct.
end ( string $cursor ) : Query The ending point for the query results.
filter ( string $property, string $operator, mixed $value ) : Query Add a filter to the query.
hasAncestor ( Key $key ) : Query Query for entities by their ancestors.
jsonSerialize ( )
keysOnly ( ) : Query Set the query to return only keys (no properties).
kind ( array | string $kinds ) : Query Set the Kind to query.
limit ( integer $num ) : Query The number of results to return.
offset ( integer $num ) : Query The number of results to skip.
order ( string $property, string $direction = self::ORDER_DEFAULT ) : Query Specify an order for the query.
projection ( array | string $properties ) : Query Set the Query Projection.
queryKey ( ) : string Return the query_type union field name.
queryObject ( ) : array Return a service-compliant array.
start ( string $cursor ) : Query The starting point for the query results.

Private Methods

Méthode Description
initializeFilter ( ) : void Setup the filter object when the first filter is created.
mapOperator ( string $operator ) : string Convert given operator to API-compatible operator.
propertyName ( string $property ) : array Format a property name.

Method Details

__construct() public méthode

public __construct ( EntityMapper $entityMapper, array $query = [] )
$entityMapper Google\Cloud\Datastore\EntityMapper An instance of EntityMapper
$query array [optional] [Query](https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#query)

canPaginate() public méthode

Indicate that this type does support automatic pagination.
public canPaginate ( ) : boolean
Résultat boolean

distinctOn() public méthode

The query results will contain the first result for each distinct combination of values for the given properties (if empty, all results are returned). Example: $query->distinctOn('lastName');
public distinctOn ( array | string $property ) : Query
$property array | string The property or properties to make distinct.
Résultat Query

end() public méthode

Example: $query->end($lastResultCursor);
See also: https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets Cursors, Limits and Offsets
public end ( string $cursor ) : Query
$cursor string The cursor on which to end the result.
Résultat Query

filter() public méthode

If the top-level filter is specified as a propertyFilter, it will be replaced. Any composite filters will be preserved and the new filter will be added. Example: $query->filter('firstName', '=', 'Bob') ->filter('lastName', '=', 'Testguy');
See also: https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#operator_1 Allowed Operators
public filter ( string $property, string $operator, mixed $value ) : Query
$property string The property to filter.
$operator string The operator to use in the filter. A list of allowed operators may be found [here](https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#operator_1). Short comparison operators are provided for convenience and are mapped to their datastore-compatible equivalents. Available short operators are `=`, `<`, `<=`, `>`, and `>=`.
$value mixed The value to check.
Résultat Query

hasAncestor() public méthode

Keys can be provided either via a {@see \Google\Cloud\Datastore\Key} object, or by providing a kind, identifier and (optionally) an identifier type. Example: $key = $datastore->key('Person', 'Bob'); $query->hasAncestor($key); Specifying an identifier type $key = $datastore->key('Robots', '1337', [ 'identifierType' => Key::TYPE_NAME ]); $query->hasAncestor($key);
public hasAncestor ( Key $key ) : Query
$key Google\Cloud\Datastore\Key The ancestor Key instance.
Résultat Query

jsonSerialize() public méthode

public jsonSerialize ( )

keysOnly() public méthode

Example: $query->keysOnly();
public keysOnly ( ) : Query
Résultat Query

kind() public méthode

If empty, returns entities of all kinds. Must be set in order to filter results. While you may supply as many kinds as you wish, datastore currently only accepts one at a time. Example: $query->kind('Person');
public kind ( array | string $kinds ) : Query
$kinds array | string The kind or kinds to return. Only a single kind is currently supported.
Résultat Query

limit() public méthode

Example: $query->limit(50);
See also: https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets Cursors, Limits and Offsets
public limit ( integer $num ) : Query
$num integer The number of results to return.
Résultat Query

offset() public méthode

Example: $query->offset(2);
See also: https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets Cursors, Limits and Offsets
public offset ( integer $num ) : Query
$num integer The number of results to skip.
Résultat Query

order() public méthode

Example: $query->order('birthDate', Query::ORDER_DESCENDING);
See also: https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#Direction Allowed Directions
public order ( string $property, string $direction = self::ORDER_DEFAULT ) : Query
$property string The property to order by.
$direction string The direction to order in.
Résultat Query

projection() public méthode

Accepts an array of properties. If set, only these properties will be returned. Example: $query->projection(['firstName', 'lastName']);
public projection ( array | string $properties ) : Query
$properties array | string The property or properties to include in the result.
Résultat Query

queryKey() public méthode

Return the query_type union field name.
public queryKey ( ) : string
Résultat string

queryObject() public méthode

This method is intended for use internally by the PHP client.
public queryObject ( ) : array
Résultat array

start() public méthode

Example: $query->start($lastResultCursor);
See also: https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets Cursors, Limits and Offsets
public start ( string $cursor ) : Query
$cursor string The cursor on which to start the result.
Résultat Query