Skip to content

Commit

Permalink
Fix Batch object creation instructions (#7341)
Browse files Browse the repository at this point in the history
Correctly specify  that a Batch object is constructed from a Database object, not a Client.
  • Loading branch information
nielm authored and tseaver committed Feb 14, 2019
1 parent fd126fd commit 01d48f2
Showing 1 changed file with 15 additions and 3 deletions.
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=[
('bharney@example.com',)
('nonesuch@example.com',)
])
with session.batch() as batch:
with database.batch() as batch:
batch.insert(
'citizens', columns=['email', 'first_name', 'last_name', 'age'],
Expand Down

0 comments on commit 01d48f2

Please sign in to comment.