Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions spanner/docs/batch-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Batching Modifications
######################

A :class:`~google.cloud.spanner.batch.Batch` represents a set of data
modification operations to be performed on tables in a dataset. Use of a
modification operations to be performed on tables in a database. Use of a
``Batch`` does not require creating an explicit
:class:`~google.cloud.spanner.snapshot.Snapshot` or
:class:`~google.cloud.spanner.transaction.Transaction`. Until
Expand All @@ -13,9 +13,17 @@ no changes are propagated to the back-end.
Starting a Batch
----------------

Construct a :class:`~google.cloud.spanner.batch.Batch` object from a :class:`~google.cloud.spanner.database.Database` object:

.. code:: python

batch = client.batch()
from google.cloud import spanner

client = spanner.Client()
instance = client.instance(INSTANCE_NAME)
database = instance.database(DATABASE_NAME)

batch = database.batch()


Inserting records using a Batch
Expand Down Expand Up @@ -159,12 +167,16 @@ if the ``with`` block exits without raising an exception.

from google.cloud.spanner.keyset import KeySet

client = spanner.Client()
instance = client.instance(INSTANCE_NAME)
database = instance.database(DATABASE_NAME)

to_delete = KeySet(keys=[
('[email protected]',)
('[email protected]',)
])

with session.batch() as batch:
with database.batch() as batch:

batch.insert(
'citizens', columns=['email', 'first_name', 'last_name', 'age'],
Expand Down