Reference documentation and code samples for the Cloud Datastore Client class Operation.
Run lookups and queries and commit changes.
This class is used by {@see} and {@see} and is not intended to be used directly.
Examples are omitted for brevity. Detailed usage examples can be found in {@see} and {@see}.
Methods
__construct
Create an operation
Parameters | |
---|---|
Name | Description |
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 |
Google\Cloud\Datastore\EntityMapper
A Datastore Entity Mapper instance. |
databaseId |
string
ID of the database to which the entities belong. |
key
Create a single Key instance
Parameters | |
---|---|
Name | Description |
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 |
↳ databaseId |
string
ID of the database to which the entities belong. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Datastore\Key |
keys
Create multiple keys with the same configuration.
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.
Parameters | |
---|---|
Name | Description |
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 | |
---|---|
Type | Description |
array<Google\Cloud\Datastore\Key> |
entity
Create an entity
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 certain cases, you may want to create your own entity types.
Google Cloud PHP supports custom types implementing
{@see}. If the name of an
EntityInterface
implementation is given in the options array, an
instance of that class will be returned instead of
{@see}.
Parameters | |
---|---|
Name | Description |
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 {@see}. Defaults to {@see}. |
↳ excludeFromIndexes |
array
A list of entity keys to exclude from datastore indexes. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Datastore\EntityInterface |
beginTransaction
Begin a Datastore Transaction.
Parameters | |
---|---|
Name | Description |
transactionOptions |
array
|
options |
array
Configuration options. |
Returns | |
---|---|
Type | Description |
string |
allocateIds
Allocate available IDs to a set of keys
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.
Parameters | |
---|---|
Name | Description |
keys |
array<Google\Cloud\Datastore\Key>
The incomplete keys. |
options |
array
[optional] Configuration Options. |
Returns | |
---|---|
Type | Description |
array<Google\Cloud\Datastore\Key> |
lookup
Lookup records by key
Parameters | |
---|---|
Name | Description |
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 {@see}. If an array is given, it must be an associative array, where the key is a Kind and the value must implement {@see}. Defaults to {@see}. |
↳ sort |
bool
If set to true, results in each set will be sorted to match the order given in $keys. Defaults to |
↳ databaseId |
string
ID of the database to which the entities belong. |
Returns | |
---|---|
Type | Description |
array | Returns an array with keys [`found`, `missing`, and `deferred`]. Members of `found` will be instance of {@see}. Members of `missing` and `deferred` will be instance of {@see}. |
runQuery
Run a query and return entities
Parameters | |
---|---|
Name | Description |
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 {@see}. Defaults to {@see}. |
↳ readConsistency |
string
See ReadConsistency. |
↳ databaseId |
string
ID of the database to which the entities belong. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Datastore\EntityIterator<\google\cloud\datastore\entityinterface> |
commit
Commit all mutations
Calling this method will end the operation (and close the transaction, if one is specified).
Parameters | |
---|---|
Name | Description |
mutations |
array
|
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 | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
entities |
array<Google\Cloud\Datastore\EntityInterface>
A list of entities |
Returns | |
---|---|
Type | Description |
array<Google\Cloud\Datastore\EntityInterface> |
mutation
Enqueue a mutation
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.
Parameters | |
---|---|
Name | Description |
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 | |
---|---|
Type | Description |
array | [Mutation](https://cloud.google.com/datastore/docs/reference/rest/v1/projects/commit#Mutation). |
rollback
Roll back a transaction
Parameter | |
---|---|
Name | Description |
transactionId |
string
The transaction to roll back |
Returns | |
---|---|
Type | Description |
void |
checkOverwrite
Check whether an update or upsert operation may proceed safely
Parameters | |
---|---|
Name | Description |
entities |
array<Google\Cloud\Datastore\EntityInterface>
the entities to be updated or upserted. |
allowOverwrite |
bool
If |
Returns | |
---|---|
Type | Description |
void |