Reference documentation and code samples for the Cloud Spanner Client class Operation.
Common interface for running operations against Cloud Spanner. This class is intended for internal use by the client library only. Implementors should access these operations via Database or Transaction.
Usage examples may be found in classes making use of this class:
Namespace
Google \ Cloud \ SpannerMethods
__construct
Parameters | |
---|---|
Name | Description |
connection |
Connection\ConnectionInterface
A connection to Google Cloud Spanner. This object is created by SpannerClient, and should not be instantiated outside of this client. |
returnInt64AsObject |
bool
If true, 64 bit integers will be returned as a Google\Cloud\Core\Int64 object for 32 bit platform compatibility. |
commit
Commit all enqueued mutations.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session ID to use for the commit. |
mutations |
array
A list of mutations to apply. |
options |
array
Configuration options. |
↳ transactionId |
string
The ID of the transaction. |
↳ returnCommitStats |
bool
If true, return the full response. Defaults to |
↳ maxCommitDelay |
Duration
The amount of latency this request is willing to incur in order to improve throughput. Defaults to null. |
↳ requestOptions |
array
Request options. For more information on available options, please see the upstream documentation. Please note, if using the |
Returns | |
---|---|
Type | Description |
Timestamp |
The commit Timestamp. |
commitWithResponse
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session ID to use for the commit. |
mutations |
array
A list of mutations to apply. |
options |
array
Configuration options. |
↳ transactionId |
string
The ID of the transaction. |
↳ returnCommitStats |
bool
If true, return the full response. Defaults to |
↳ maxCommitDelay |
Duration
The amount of latency this request is willing to incur in order to improve throughput. Defaults to null. |
↳ requestOptions |
array
Request options. For more information on available options, please see the upstream documentation. Please note, if using the |
Returns | |
---|---|
Type | Description |
array |
An array containing {@see \Google\Cloud\Spanner\Timestamp} at index 0 and the commit response as an array at index 1. |
rollback
Rollback a Transaction.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session to use for the rollback. Note that the session MUST be the same one in which the transaction was created. |
transactionId |
string
The transaction to roll back. |
options |
array
[optional] Configuration Options. |
Returns | |
---|---|
Type | Description |
void |
execute
Run a query.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session to use to execute the SQL. |
sql |
string
The query string. |
options |
array
Configuration options. |
↳ requestOptions |
array
Request options. For more information on available options, please see the upstream documentation. Please note, if using the |
↳ transaction |
array
Transaction selector options. |
↳ transaction |
array
.begin The begin transaction options. Refer |
↳ directedReadOptions |
array
Directed read options. V1\DirectedReadOptions If using the |
Returns | |
---|---|
Type | Description |
Result |
executeUpdate
Execute a DML statement and return an affected row count.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session in which the update operation should be executed. |
transaction |
Transaction
The transaction in which the operation should be executed. |
sql |
string
The SQL string to execute. |
options |
array
Configuration options. |
↳ requestOptions |
array
Request options. For more information on available options, please see the upstream documentation. Please note, if using the |
↳ transaction |
array
Transaction selector options. |
↳ transaction |
array
.begin The begin transaction options. Refer |
Returns | |
---|---|
Type | Description |
int |
executeUpdateBatch
Execute multiple DML statements.
For detailed usage instructions, see Transaction::executeUpdateBatch().
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session in which the update operation should be executed. |
transaction |
Transaction
The transaction in which the operation should be executed. |
statements |
array[]
A list of DML statements to run. Each statement
must contain a |
options |
array
Configuration Options. |
↳ requestOptions |
array
Request options. For more information on available options, please see the upstream documentation. Please note, if using the |
↳ transaction |
array
Transaction selector options. |
↳ transaction |
array
.begin The begin transaction options. Refer |
Returns | |
---|---|
Type | Description |
BatchDmlResult |
read
Lookup rows in a database.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session in which to read data. |
table |
string
The table name. |
keySet |
KeySet
The KeySet to select rows. |
columns |
array
A list of column names to return. |
options |
array
Configuration Options. |
↳ index |
string
The name of an index on the table. |
↳ offset |
int
The number of rows to offset results by. |
↳ limit |
int
The number of results to return. |
↳ requestOptions |
array
Request options. For more information on available options, please see the upstream documentation. Please note, if using the |
↳ transaction |
array
Transaction selector options. |
↳ transaction |
array
.begin The begin transaction options. Refer |
↳ directedReadOptions |
array
Directed read options. V1\DirectedReadOptions If using the |
Returns | |
---|---|
Type | Description |
Result |
transaction
See also:
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session to start the transaction in. |
options |
array
Configuration Options. |
↳ singleUse |
bool
If true, a Transaction ID will not be allocated up front. Instead, the transaction will be considered "single-use", and may be used for only a single operation. Defaults to |
↳ isRetry |
bool
If true, the resulting transaction will indicate that it is the result of a retry operation. Defaults to |
↳ begin |
array
The begin transaction options. Refer |
Returns | |
---|---|
Type | Description |
Transaction |
createTransaction
Create a Transaction instance from a response object.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session the transaction belongs to. |
res |
array
[optional] The createTransaction response. |
options |
array
[optional] Options for the transaction object. @type array $begin The begin transaction options. Refer |
Returns | |
---|---|
Type | Description |
Transaction |
snapshot
See also:
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session to start the snapshot in. |
options |
array
Configuration Options. |
↳ singleUse |
bool
If true, a Transaction ID will not be allocated up front. Instead, the transaction will be considered "single-use", and may be used for only a single operation. Defaults to |
↳ className |
string
If set, an instance of the given class will be instantiated. This setting is intended for internal use. Defaults to |
↳ directedReadOptions |
array
Directed read options. V1\DirectedReadOptions If using the |
Returns | |
---|---|
Type | Description |
mixed |
createSnapshot
Create a Snapshot instance from a response object.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session the snapshot belongs to. |
res |
array
[optional] The createTransaction response. |
className |
string
[optional] The class to instantiate with a
snapshot. Defaults to |
Returns | |
---|---|
Type | Description |
mixed |
createSession
Create a new session.
Sessions are handled behind the scenes and this method does not need to be called directly.
Parameters | |
---|---|
Name | Description |
databaseName |
string
The database name |
options |
array
Configuration options. |
↳ labels |
array
Labels to be applied to each session created in the pool. Label keys must be between 1 and 63 characters long and must conform to the following regular expression: |
↳ creator_role |
string
The user created database role which creates the session. |
Returns | |
---|---|
Type | Description |
Session\Session |
session
Lazily instantiates a session. There are no network requests made at this point. To see the operations that can be performed on a session please see Session\Session.
Sessions are handled behind the scenes and this method does not need to be called directly.
Parameter | |
---|---|
Name | Description |
sessionName |
string
The session's name. |
Returns | |
---|---|
Type | Description |
Session\Session |
partitionQuery
Begin a partitioned SQL query.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session to run in. |
transactionId |
string
The transaction to run in. |
sql |
string
The query string to execute. |
options |
array
Configuration Options |
↳ maxPartitions |
int
The desired maximum number of partitions to return. For example, this may be set to the number of workers available. The maximum value is currently 200,000. This is only a hint. The actual number of partitions returned may be smaller than this maximum count request. Defaults to |
↳ partitionSizeBytes |
int
The desired data size for each partition generated. This is only a hint. The actual size of each partition may be smaller or larger than this size request. Defaults to |
↳ parameters |
array
A key/value array of Query Parameters, where the key is represented in the query string prefixed by a |
↳ types |
array
A key/value array of Query Parameter types. Generally, Google Cloud PHP can infer types. Explicit type definitions are only necessary for null parameter values. Accepted values are defined as constants on ValueMapper, and are as follows: |
Returns | |
---|---|
Type | Description |
array<Batch\QueryPartition> |
partitionRead
Begin a partitioned read.
Parameters | |
---|---|
Name | Description |
session |
Session\Session
The session to run in. |
transactionId |
string
The transaction to run in. |
table |
string
The table name. |
keySet |
KeySet
The KeySet to select rows. |
columns |
array
A list of column names to return. |
options |
array
Configuration Options |
↳ maxPartitions |
int
The desired maximum number of partitions to return. For example, this may be set to the number of workers available. The maximum value is currently 200,000. This is only a hint. The actual number of partitions returned may be smaller than this maximum count request. Defaults to |
↳ partitionSizeBytes |
int
The desired data size for each partition generated. This is only a hint. The actual size of each partition may be smaller or larger than this size request. Defaults to |
↳ index |
string
The name of an index on the table. |
Returns | |
---|---|
Type | Description |
array<Batch\ReadPartition> |
__debugInfo
Represent the class in a more readable and digestable fashion.
Constants
OP_INSERT
Value: 'insert'
OP_UPDATE
Value: 'update'
OP_INSERT_OR_UPDATE
Value: 'insertOrUpdate'
OP_REPLACE
Value: 'replace'
OP_DELETE
Value: 'delete'