Cloud Datastore Client - Class Operation (1.24.4)

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

Run lookups and queries and commit changes.

This class is used by Google\Cloud\Datastore\DatastoreClient and Google\Cloud\Datastore\Transaction and is not intended to be used directly.

Examples are omitted for brevity. Detailed usage examples can be found in Google\Cloud\Datastore\DatastoreClient and Google\Cloud\Datastore\Transaction.

Namespace

Google \ Cloud \ Datastore

Methods

__construct

Create an operation

Parameters
NameDescription
connection Google\Cloud\Datastore\Connection\ConnectionInterface

A connection to Google Cloud Platform's Datastore API. This object is created by DatastoreClient, and should not be instantiated outside of this client.

projectId string

The Google Cloud Platform project ID.

namespaceId string

The namespace to use for all service requests.

entityMapper Google\Cloud\Datastore\EntityMapper

A Datastore Entity Mapper instance.

databaseId string

ID of the database to which the entities belong.

key

See also:

Parameters
NameDescription
kind string

The kind.

identifier string|int

[optional] The ID or name.

options array

Configuration Options

↳ identifierType string

If omitted, type will be determined internally. In cases where any ambiguity can be expected (i.e. if you want to create keys with name but your values may pass PHP's is_numeric() check), this value may be explicitly set using Key::TYPE_ID or Key::TYPE_NAME.

↳ databaseId string

ID of the database to which the entities belong.

Returns
TypeDescription
Google\Cloud\Datastore\Key

keys

See also:

Parameters
NameDescription
kind string

The kind to use in the final path element.

options array

Configuration Options

↳ ancestors array[]

An array of PathElement arrays. Use to create ancestor paths.

↳ number int

The number of keys to generate.

↳ id string|int

The ID for the last pathElement.

↳ name string

The Name for the last pathElement.

Returns
TypeDescription
array<Google\Cloud\Datastore\Key>

entity

See also:

Parameters
NameDescription
key Google\Cloud\Datastore\Key|string|null

[optional] The key used to identify the record, or a string $kind. The key may be null only if the entity will be used as an embedded entity within another entity. Attempting to use keyless entities as root entities will result in error.

entity array

[optional] The data to fill the entity with.

options array

Configuration Options

↳ className string

If set, the given class will be returned. Value must be the name of a class implementing Google\Cloud\Datastore\EntityInterface. Defaults to Google\Cloud\Datastore\Entity.

↳ excludeFromIndexes array

A list of entity keys to exclude from datastore indexes.

Returns
TypeDescription
Google\Cloud\Datastore\EntityInterface

beginTransaction

Begin a Datastore Transaction.

Parameters
NameDescription
transactionOptions array

Transaction Options

options array

Configuration options.

Returns
TypeDescription
string

allocateIds

See also:

Parameters
NameDescription
keys array<Google\Cloud\Datastore\Key>

The incomplete keys.

options array

[optional] Configuration Options.

Returns
TypeDescription
array<Google\Cloud\Datastore\Key>

lookup

Lookup records by key

Parameters
NameDescription
keys array<Google\Cloud\Datastore\Key>

The identifiers to look up.

options array

Configuration Options

↳ readConsistency string

See ReadConsistency.

↳ transaction string

The transaction ID, if the query should be run in a transaction.

↳ className string|array

If a string, the given class will be returned. Value must be the name of a class implementing Google\Cloud\Datastore\EntityInterface. If an array is given, it must be an associative array, where the key is a Kind and the value must implement Google\Cloud\Datastore\EntityInterface. Defaults to Google\Cloud\Datastore\Entity.

↳ sort bool

If set to true, results in each set will be sorted to match the order given in $keys. Defaults to false.

↳ databaseId string

ID of the database to which the entities belong.

↳ readTime Timestamp

Reads entities as they were at the given timestamp.

Returns
TypeDescription
arrayReturns an array with keys [`found`, `missing`, and `deferred`]. Members of `found` will be instance of {@see \Google\Cloud\Datastore\Entity}. Members of `missing` and `deferred` will be instance of {@see \Google\Cloud\Datastore\Key}.

runQuery

Run a query and return entities

Parameters
NameDescription
query Google\Cloud\Datastore\Query\QueryInterface

The query object.

options array

Configuration Options

↳ transaction string

The transaction ID, if the query should be run in a transaction.

↳ className string

If set, the given class will be returned. Value must be the name of a class implementing Google\Cloud\Datastore\EntityInterface. Defaults to Google\Cloud\Datastore\Entity.

↳ readConsistency string

See ReadConsistency.

↳ databaseId string

ID of the database to which the entities belong.

↳ readTime Timestamp

Reads entities as they were at the given timestamp.

Returns
TypeDescription
Google\Cloud\Datastore\EntityIterator<\google\cloud\datastore\entityinterface>

runAggregationQuery

Run an aggregation query and return aggregated results.

Parameters
NameDescription
runQueryObj Google\Cloud\Datastore\Query\AggregationQuery
options array

Configuration Options

↳ transaction string

The transaction ID, if the query should be run in a transaction.

↳ readConsistency string

See ReadConsistency.

↳ databaseId string

ID of the database to which the entities belong.

↳ readTime Timestamp

Reads entities as they were at the given timestamp.

Returns
TypeDescription
Google\Cloud\Datastore\Query\AggregationQueryResult

commit

Commit all mutations

Calling this method will end the operation (and close the transaction, if one is specified).

Parameters
NameDescription
mutations array

Mutation[].

options array

Configuration Options

↳ transaction string

The transaction ID, if the query should be run in a transaction.

↳ databaseId string

ID of the database to which the entities belong.

Returns
TypeDescription
array[Response Body](https://cloud.google.com/datastore/reference/rest/v1/projects/commit#response-body)

allocateIdsToEntities

Patch any incomplete keys in the given array of entities

Any incomplete keys will be allocated an ID. Named keys in the input will remain unchanged.

Parameter
NameDescription
entities array<Google\Cloud\Datastore\EntityInterface>

A list of entities

Returns
TypeDescription
array<Google\Cloud\Datastore\EntityInterface>

mutation

See also:

Parameters
NameDescription
operation string

The operation to execute. "Insert", "Upsert", "Update" or "Delete".

input Google\Cloud\Datastore\EntityInterface|Google\Cloud\Datastore\Key

The entity or key to mutate.

type string

The type of the input array.

baseVersion string

[optional] The version of the entity that this mutation is being applied to. If this does not match the current version on the server, the mutation conflicts.

Returns
TypeDescription
array[Mutation](https://cloud.google.com/datastore/docs/reference/rest/v1/projects/commit#Mutation).

rollback

Roll back a transaction

Parameter
NameDescription
transactionId string

The transaction to roll back

Returns
TypeDescription
void

checkOverwrite

Check whether an update or upsert operation may proceed safely

Parameters
NameDescription
entities array<Google\Cloud\Datastore\EntityInterface>

the entities to be updated or upserted.

allowOverwrite bool

If true, entities may be overwritten. Defaults to false.

Returns
TypeDescription
void