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 Google\Cloud\Spanner\Database or Google\Cloud\Spanner\Transaction.
Usage examples may be found in classes making use of this class:
- {@see}
- {@see}
Methods
__construct
Parameters | |
---|---|
Name | Description |
connection |
Google\Cloud\Spanner\Connection\ConnectionInterface
A connection to Google Cloud Spanner. |
returnInt64AsObject |
bool
If true, 64 bit integers will be returned as a {@see} object for 32 bit platform compatibility. |
mutation
Create a formatted mutation.
Parameters | |
---|---|
Name | Description |
operation |
string
The operation type. |
table |
string
The table name. |
mutation |
array
The mutation data, represented as a set of key/value pairs. |
Returns | |
---|---|
Type | Description |
array |
deleteMutation
Create a formatted delete mutation.
Parameters | |
---|---|
Name | Description |
table |
string
The table name. |
keySet |
Google\Cloud\Spanner\KeySet
The keys to delete. |
Returns | |
---|---|
Type | Description |
array |
commit
Commit all enqueued mutations.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\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 |
↳ requestOptions |
array
Request options. For more information on available options, please see the upstream documentation. Please note, if using the |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Timestamp | The commit Timestamp. |
rollback
Rollback a Transaction.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\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 |
Google\Cloud\Spanner\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 |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Result |
executeUpdate
Execute a DML statement and return an affected row count.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\Session\Session
The session in which the update operation should be executed. |
transaction |
Google\Cloud\Spanner\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 |
Returns | |
---|---|
Type | Description |
int |
executeUpdateBatch
Execute multiple DML statements.
For detailed usage instructions, see {@see}.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\Session\Session
The session in which the update operation should be executed. |
transaction |
Google\Cloud\Spanner\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 |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\BatchDmlResult |
read
Lookup rows in a database.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\Session\Session
The session in which to read data. |
table |
string
The table name. |
keySet |
Google\Cloud\Spanner\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 |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Result |
transaction
Create a read/write transaction.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\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 |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Transaction |
createTransaction
Create a Transaction instance from a response object.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\Session\Session
The session the transaction belongs to. |
res |
array
[optional] The createTransaction response. |
options |
array
[optional] Options for the transaction object. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Transaction |
snapshot
Create a read-only snapshot transaction.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\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 |
Returns | |
---|---|
Type | Description |
mixed |
createSnapshot
Create a Snapshot instance from a response object.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\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: |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\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 Google\Cloud\Spanner\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 |
Google\Cloud\Spanner\Session\Session |
partitionQuery
Begin a partitioned SQL query.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\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 {@see}, and are as follows: |
Returns | |
---|---|
Type | Description |
array<Google\Cloud\Spanner\Batch\QueryPartition> |
partitionRead
Begin a partitioned read.
Parameters | |
---|---|
Name | Description |
session |
Google\Cloud\Spanner\Session\Session
The session to run in. |
transactionId |
string
The transaction to run in. |
table |
string
The table name. |
keySet |
Google\Cloud\Spanner\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<Google\Cloud\Spanner\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'