Skip to content

Commit 489fe17

Browse files
nielmtseaver
authored andcommitted
Fix Batch object creation instructions (#7341)
Correctly specify that a Batch object is constructed from a Database object, not a Client.
1 parent e1f41b1 commit 489fe17

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

packages/google-cloud-spanner/docs/batch-usage.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Batching Modifications
22
######################
33

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

16+
Construct a :class:`~google.cloud.spanner.batch.Batch` object from a :class:`~google.cloud.spanner.database.Database` object:
17+
1618
.. code:: python
1719
18-
batch = client.batch()
20+
from google.cloud import spanner
21+
22+
client = spanner.Client()
23+
instance = client.instance(INSTANCE_NAME)
24+
database = instance.database(DATABASE_NAME)
25+
26+
batch = database.batch()
1927
2028
2129
Inserting records using a Batch
@@ -159,12 +167,16 @@ if the ``with`` block exits without raising an exception.
159167
160168
from google.cloud.spanner.keyset import KeySet
161169
170+
client = spanner.Client()
171+
instance = client.instance(INSTANCE_NAME)
172+
database = instance.database(DATABASE_NAME)
173+
162174
to_delete = KeySet(keys=[
163175
('bharney@example.com',)
164176
('nonesuch@example.com',)
165177
])
166178
167-
with session.batch() as batch:
179+
with database.batch() as batch:
168180
169181
batch.insert(
170182
'citizens', columns=['email', 'first_name', 'last_name', 'age'],

0 commit comments

Comments
 (0)