Batch API¶
Context manager for Cloud Spanner batched writes.
- class google.cloud.spanner_v1.batch.Batch(session)[source]¶
Bases:
google.cloud.spanner_v1.batch._BatchBase
Accumulate mutations for transmission during
commit()
.- commit(return_commit_stats=False, request_options=None, max_commit_delay=None, exclude_txn_from_change_streams=False)[source]¶
Commit mutations to the database.
- Parameters
return_commit_stats (bool) – If true, the response will return commit stats which can be accessed though commit_stats.
request_options (
google.cloud.spanner_v1.types.RequestOptions
) – (Optional) Common options for this request. If a dict is provided, it must be of the same form as the protobuf messageRequestOptions
.max_commit_delay (
datetime.timedelta
) – (Optional) The amount of latency this request is willing to incur in order to improve throughput.
- Return type
datetime
- Returns
timestamp of the committed changes.
- commit_stats = None¶
Timestamp at which the batch was successfully committed.
- class google.cloud.spanner_v1.batch.MutationGroup(session, mutations=[])[source]¶
Bases:
google.cloud.spanner_v1.batch._BatchBase
A container for mutations.
Clients should use
MutationGroups
to obtain instances instead of directly creating instances.
- class google.cloud.spanner_v1.batch.MutationGroups(session)[source]¶
Bases:
google.cloud.spanner_v1._helpers._SessionWrapper
Accumulate mutation groups for transmission during
batch_write()
.- Parameters
session (
Session
) – the session used to perform the commit
- batch_write(request_options=None, exclude_txn_from_change_streams=False)[source]¶
Executes batch_write.
- Parameters
request_options (
google.cloud.spanner_v1.types.RequestOptions
) – (Optional) Common options for this request. If a dict is provided, it must be of the same form as the protobuf messageRequestOptions
.exclude_txn_from_change_streams (bool) – (Optional) If true, instructs the transaction to be excluded from being recorded in change streams with the DDL option allow_txn_exclusion=true. This does not exclude the transaction from being recorded in the change streams with the DDL option allow_txn_exclusion being false or unset.
- Return type
Iterable[google.cloud.spanner_v1.types.BatchWriteResponse]
- Returns
a sequence of responses for each batch.