PHP Class Google\Cloud\Datastore\Operation

This class is used by {@see \Google\Cloud\Datastore\DatastoreClient} and {@see \Google\Cloud\Datastore\Transaction} and is not intended to be used directly. Examples are omitted for brevity. Detailed usage examples can be found in {@see \Google\Cloud\Datastore\DatastoreClient} and {@see \Google\Cloud\Datastore\Transaction}.
Inheritance: use trait DatastoreTrait, use trait Google\Cloud\ValidateTrait
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php Class Usage Examples

Protected Properties

Property Type Description
$connection Google\Cloud\Datastore\Connection\ConnectionInterface

Public Methods

Method Description
__construct ( Google\Cloud\Datastore\Connection\ConnectionInterface $connection, string $projectId, string $namespaceId, EntityMapper $entityMapper ) Create an operation
allocateIds ( array $keys, array $options = [] ) : Key[] Allocate available IDs to a set of keys
allocateIdsToEntities ( array $entities ) : Entity[] Patch any incomplete keys in the given array of entities
checkOverwrite ( array $entities, boolean $allowOverwrite = false ) : void Check whether an update or upsert operation may proceed safely
commit ( array $mutations, array $options = [] ) : array Commit all mutations
entity ( Key | string $key, array $entity = [], array $options = [] ) : Entity Create an entity
key ( string $kind, string | integer $identifier = null, array $options = [] ) : Key Create a single Key instance
keys ( string $kind, array $options = [] ) : Key[] Create multiple keys with the same configuration.
lookup ( array $keys, array $options = [] ) : array Lookup records by key
mutation ( string $operation, Entity | Key $input, string $type, string $baseVersion = null ) : array Enqueue a mutation
rollback ( string $transactionId ) : void Roll back a transaction
runQuery ( Google\Cloud\Datastore\Query\QueryInterface $query, array $options = [] ) : Generator Run a query and return entities

Private Methods

Method Description
mapEntityResult ( array $entityResult, string | array $class ) : Entity[] Convert an EntityResult into an array of entities
readOptions ( array $options = [] ) : array Format the readOptions
sortEntities ( array $entities, array $keys ) : Entity[] Sort entities into the order given in $keys.

Method Details

__construct() public method

Create an operation
public __construct ( Google\Cloud\Datastore\Connection\ConnectionInterface $connection, string $projectId, string $namespaceId, EntityMapper $entityMapper )
$connection Google\Cloud\Datastore\Connection\ConnectionInterface A connection to Google Cloud Platform's Datastore API.
$projectId string The Google Cloud Platform project ID.
$namespaceId string The namespace to use for all service requests.
$entityMapper EntityMapper

allocateIds() public method

Keys MUST be in an incomplete state (i.e. including a kind but not an ID or name in their final pathElement). This method will execute a service request.
See also: https://cloud.google.com/datastore/reference/rest/v1/projects/allocateIds allocateIds
public allocateIds ( array $keys, array $options = [] ) : Key[]
$keys array The incomplete keys.
$options array [optional] Configuration Options.
return Key[]

allocateIdsToEntities() public method

Any incomplete keys will be allocated an ID. Named keys in the input will remain unchanged.
public allocateIdsToEntities ( array $entities ) : Entity[]
$entities array A list of entities
return Entity[]

checkOverwrite() public method

Check whether an update or upsert operation may proceed safely
public checkOverwrite ( array $entities, boolean $allowOverwrite = false ) : void
$entities array the entities to be updated or upserted.
$allowOverwrite boolean If `true`, entities may be overwritten. **Defaults to** `false`.
return void

commit() public method

Calling this method will end the operation (and close the transaction, if one is specified).
public commit ( array $mutations, array $options = [] ) : array
$mutations array [Mutation[]](https://cloud.google.com/datastore/docs/reference/rest/v1/projects/commit#Mutation).
$options array [optional] { Configuration Options @type string $transaction The transaction ID, if the query should be run in a transaction. }
return array [Response Body](https://cloud.google.com/datastore/reference/rest/v1/projects/commit#response-body)

entity() public method

This method does not execute any service requests. Entities are created with a Datastore Key, or by specifying a Kind. Kinds are only allowed for insert operations. For any other case, you must specify a named key. If a kind is given, an ID will be automatically allocated for the entity upon insert. Additionally, if your entity requires a complex key elementPath, you must create the key separately. In complex applications you may want to create your own entity types. Google Cloud PHP supports subclassing of {@see \Google\Cloud\Datastore\Entity}. If the name of a subclass of Entity is given in the options array, an instance of the subclass will be returned instead of Entity.
See also: https://cloud.google.com/datastore/reference/rest/v1/Entity Entity
public entity ( Key | string $key, array $entity = [], array $options = [] ) : Entity
$key Key | string The key used to identify the record, or a string $kind.
$entity array [optional] The data to fill the entity with.
$options array [optional] { Configuration Options @type string $className The name of a class extending {@see \Google\Cloud\Datastore\Entity}. If provided, an instance of that class will be returned instead of Entity. If not set, {@see \Google\Cloud\Datastore\Entity} will be used. @type array $excludeFromIndexes A list of entity keys to exclude from datastore indexes. }
return Entity

key() public method

Create a single Key instance
See also: https://cloud.google.com/datastore/reference/rest/v1/Key Key
See also: https://cloud.google.com/datastore/reference/rest/v1/Key#PathElement PathElement
public key ( string $kind, string | integer $identifier = null, array $options = [] ) : Key
$kind string The kind.
$identifier string | integer [optional] The ID or name.
$options array [optional] { Configuration Options @type string $identifierType 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`. }
return Key

keys() public method

When inserting multiple entities, creating a set of keys at once can be useful. By defining the Key's kind and any ancestors up front, and allowing Cloud Datastore to allocate IDs, you can be sure that your entity identity and ancestry are correct and that there will be no collisions during the insert operation.
See also: https://cloud.google.com/datastore/reference/rest/v1/Key Key
See also: https://cloud.google.com/datastore/reference/rest/v1/Key#PathElement PathElement
public keys ( string $kind, array $options = [] ) : Key[]
$kind string The kind to use in the final path element.
$options array [optional] { Configuration Options @type array[] $ancestors An array of [PathElement](https://cloud.google.com/datastore/reference/rest/v1/Key#PathElement) arrays. Use to create [ancestor paths](https://cloud.google.com/datastore/docs/concepts/entities#ancestor_paths). @type int $number The number of keys to generate. @type string|int $id The ID for the last pathElement. @type string $name The Name for the last pathElement. }
return Key[]

lookup() public method

Lookup records by key
public lookup ( array $keys, array $options = [] ) : array
$keys array The identifiers to look up.
$options array [optional] { Configuration Options @type string $readConsistency See [ReadConsistency](https://cloud.google.com/datastore/reference/rest/v1/ReadOptions#ReadConsistency). @type string $transaction The transaction ID, if the query should be run in a transaction. @type string|array $className If a string, the name of the class to return results as. Must be a subclass of {@see \Google\Cloud\Datastore\Entity}. If not set, {@see \Google\Cloud\Datastore\Entity} will be used. If an array is given, it must be an associative array, where the key is a Kind and the value is the name of a subclass of {@see \Google\Cloud\Datastore\Entity}. @type bool $sort If set to true, results in each set will be sorted to match the order given in $keys. **Defaults to** `false`. }
return array Returns 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}.

mutation() public method

A mutation is a change to the datastore. Create, Update and Delete are examples of mutations, while Read is not. Google Cloud Datastore supports multiple mutations in a single API call, subject to the limits of the service. Adding mutations separately from committing the changes allows you to create complex operations, both inside a transaction and not.
See also: https://cloud.google.com/datastore/docs/concepts/limits Limits
public mutation ( string $operation, Entity | Key $input, string $type, string $baseVersion = null ) : array
$operation string The operation to execute. "Insert", "Upsert", "Update" or "Delete".
$input Entity | 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.
return array [Mutation](https://cloud.google.com/datastore/docs/reference/rest/v1/projects/commit#Mutation).

rollback() public method

Roll back a transaction
public rollback ( string $transactionId ) : void
$transactionId string The transaction to roll back
return void

runQuery() public method

Run a query and return entities
public runQuery ( Google\Cloud\Datastore\Query\QueryInterface $query, array $options = [] ) : Generator
$query Google\Cloud\Datastore\Query\QueryInterface The query object.
$options array [optional] { Configuration Options @type string $transaction The transaction ID, if the query should be run in a transaction. @type string $className The name of the class to return results as. Must be a subclass of {@see \Google\Cloud\Datastore\Entity}. If not set, {@see \Google\Cloud\Datastore\Entity} will be used. @type string $readConsistency See [ReadConsistency](https://cloud.google.com/datastore/reference/rest/v1/ReadOptions#ReadConsistency). }
return Generator

Property Details

$connection protected_oe property

protected ConnectionInterface,Google\Cloud\Datastore\Connection $connection
return Google\Cloud\Datastore\Connection\ConnectionInterface