PHP Класс 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);
См. также: https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#query Query Object Reference
См. также: https://cloud.google.com/datastore/docs/concepts/queries Datastore Queries
Наследование: implements Google\Cloud\Datastore\Query\QueryInterface, use trait Google\Cloud\Datastore\DatastoreTrait
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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() публичный Метод

Indicate that this type does support automatic pagination.
public canPaginate ( ) : boolean
Результат boolean

distinctOn() публичный Метод

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.
Результат Query

end() публичный Метод

Example: $query->end($lastResultCursor);
См. также: 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.
Результат Query

filter() публичный Метод

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');
См. также: 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.
Результат Query

hasAncestor() публичный Метод

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.
Результат Query

jsonSerialize() публичный Метод

public jsonSerialize ( )

keysOnly() публичный Метод

Example: $query->keysOnly();
public keysOnly ( ) : Query
Результат Query

kind() публичный Метод

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.
Результат Query

limit() публичный Метод

Example: $query->limit(50);
См. также: 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.
Результат Query

offset() публичный Метод

Example: $query->offset(2);
См. также: 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.
Результат Query

order() публичный Метод

Example: $query->order('birthDate', Query::ORDER_DESCENDING);
См. также: 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.
Результат Query

projection() публичный Метод

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.
Результат Query

queryKey() публичный Метод

Return the query_type union field name.
public queryKey ( ) : string
Результат string

queryObject() публичный Метод

This method is intended for use internally by the PHP client.
public queryObject ( ) : array
Результат array

start() публичный Метод

Example: $query->start($lastResultCursor);
См. также: 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.
Результат Query