@@ -5,7 +5,8 @@ A :class:`~google.cloud.spanner_v1.transaction.Transaction` represents a
5
5
transaction: when the transaction commits, it will send any accumulated
6
6
mutations to the server.
7
7
8
- To understand more about how transactions work, visit [Transaction](https://cloud.google.com/spanner/docs/reference/rest/v1/Transaction).
8
+ To understand more about how transactions work, visit
9
+ `Transaction <https://cloud.google.com/spanner/docs/reference/rest/v1/Transaction >`_.
9
10
To learn more about how to use them in the Python client, continue reading.
10
11
11
12
@@ -90,8 +91,8 @@ any of the records already exists.
90
91
Update records using a Transaction
91
92
----------------------------------
92
93
93
- :meth: `Transaction.update ` updates one or more existing records in a table. Fails
94
- if any of the records does not already exist.
94
+ :meth: `Transaction.update ` updates one or more existing records in a table.
95
+ Fails if any of the records does not already exist.
95
96
96
97
.. code :: python
97
98
@@ -178,35 +179,40 @@ Using :meth:`~Database.run_in_transaction`
178
179
179
180
Rather than calling :meth: `~Transaction.commit ` or :meth: `~Transaction.rollback `
180
181
manually, you should use :meth: `~Database.run_in_transaction ` to run the
181
- function that you need. The transaction's :meth: `~Transaction.commit ` method
182
+ function that you need. The transaction's :meth: `~Transaction.commit ` method
182
183
will be called automatically if the ``with `` block exits without raising an
183
- exception. The function will automatically be retried for
184
+ exception. The function will automatically be retried for
184
185
:class: `~google.api_core.exceptions.Aborted ` errors, but will raise on
185
186
:class: `~google.api_core.exceptions.GoogleAPICallError ` and
186
187
:meth: `~Transaction.rollback ` will be called on all others.
187
188
188
189
.. code :: python
189
190
190
191
def _unit_of_work (transaction ):
191
-
192
192
transaction.insert(
193
- ' citizens' , columns = [' email' , ' first_name' , ' last_name' , ' age' ],
193
+ ' citizens' ,
194
+ columns = [' email' , ' first_name' , ' last_name' , ' age' ],
194
195
values = [
195
196
[' phred@exammple.com' , ' Phred' , ' Phlyntstone' , 32 ],
196
197
[' bharney@example.com' , ' Bharney' , ' Rhubble' , 31 ],
197
- ])
198
+ ]
199
+ )
198
200
199
201
transaction.update(
200
- ' citizens' , columns = [' email' , ' age' ],
202
+ ' citizens' ,
203
+ columns = [' email' , ' age' ],
201
204
values = [
202
205
[' phred@exammple.com' , 33 ],
203
206
[' bharney@example.com' , 32 ],
204
- ])
207
+ ]
208
+ )
205
209
206
210
...
207
211
208
- transaction.delete(' citizens' ,
209
- keyset[' bharney@example.com' , ' nonesuch@example.com' ])
212
+ transaction.delete(
213
+ ' citizens' ,
214
+ keyset = [' bharney@example.com' , ' nonesuch@example.com' ]
215
+ )
210
216
211
217
db.run_in_transaction(_unit_of_work)
212
218
@@ -242,7 +248,7 @@ If an exception is raised inside the ``with`` block, the transaction's
242
248
...
243
249
244
250
transaction.delete(' citizens' ,
245
- keyset[' bharney@example.com' , ' nonesuch@example.com' ])
251
+ keyset = [' bharney@example.com' , ' nonesuch@example.com' ])
246
252
247
253
248
254
Begin a Transaction
0 commit comments