Cloud Datastore Client - Class Filter (1.22.1)

Reference documentation and code samples for the Cloud Datastore Client class Filter.

Represents an interface to create composite and property filters for Google\Cloud\Datastore\Query\Query via static methods.

Each method returns an array representation of respective filter which is consumed by other filters or Query object.

Example:

$filter = Filter::where('CompanyName', '=', 'Google');
$query = $datastore->query();
$query->kind('Companies');
$query->filter($filter);
$results = $datastore->runQuery($query);
$finalResult = [];
foreach ($results as $result) {
    $finalResult[] = $result['companyName'];
}

Composite filters can be created by using other composite/property filters.

// Or filter
$filterType = 'or';
$filterOr = Filter::or([$filter, ...$filters]);
$query = $datastore->query();
$query->kind('Companies');
$query->filter($filter);
$results = $datastore->runQuery($query);
$finalResult = [];
foreach ($results as $result) {
    $finalResult[] = $result['companyName'];
}

Similaryly, AND filter can be created using Filter::and method.

Namespace

Google \ Cloud \ Datastore \ Query

Methods

static::where

Creates a property filter in array format.

Parameters
NameDescription
property string

Property name

operator string

Operator, one of ('=', '<', '<=', '>', '>=', '!=', 'IN', 'NOT IN')

value mixed

Value for operation on property

Returns
TypeDescription
arrayReturns array representation of a property filter.

static::and

Creates an AND composite filter in array format.

Parameter
NameDescription
filters array

An array of filters(array representations) to AND upon.

Returns
TypeDescription
arrayReturns array representation of AND composite filter.

static::or

Creates a OR composite filter in array format.

Parameter
NameDescription
filters array

An array of filters(array representations) to OR upon.

Returns
TypeDescription
arrayReturns array representation of OR composite filter.