Skip to content

Commit 613d9c8

Browse files
authored
docs: update documentation for snapshot usage (#94)
Co-authored-by: larkee <larkee@users.noreply.github.com>
1 parent 44e398c commit 613d9c8

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

docs/snapshot-usage.rst

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Read-only Transactions via Snapshots
22
####################################
33

4-
A :class:`~google.cloud.spanner.snapshot.Snapshot` represents a read-only
5-
transaction: when multiple read operations are peformed via a Snapshot,
4+
A :class:`~google.cloud.spanner_v1.snapshot.Snapshot` represents a read-only
5+
transaction: when multiple read operations are performed via a Snapshot,
66
the results are consistent as of a particular point in time.
77

88

@@ -15,7 +15,8 @@ transactions are visible:
1515

1616
.. code:: python
1717
18-
snapshot = database.snapshot()
18+
with database.snapshot() as snapshot:
19+
...
1920
2021
You can also specify a weaker bound, which can either be to perform all
2122
reads as of a given timestamp:
@@ -25,15 +26,19 @@ reads as of a given timestamp:
2526
import datetime
2627
from pytz import UTC
2728
TIMESTAMP = datetime.datetime.utcnow().replace(tzinfo=UTC)
28-
snapshot = database.snapshot(read_timestamp=TIMESTAMP)
29+
30+
with database.snapshot(read_timestamp=TIMESTAMP) as snapshot:
31+
...
2932
3033
or as of a given duration in the past:
3134

3235
.. code:: python
3336
3437
import datetime
3538
DURATION = datetime.timedelta(seconds=5)
36-
snapshot = database.snapshot(exact_staleness=DURATION)
39+
40+
with database.snapshot(exact_staleness=DURATION) as snapshot:
41+
...
3742
3843
Single Use and Multiple Use Snapshots
3944
-------------------------------------
@@ -48,18 +53,19 @@ reused.
4853

4954
.. code:: python
5055
51-
snapshot = database.snapshot(multi_use=True)
56+
with database.snapshot(multi_use=True) as snapshot:
57+
...
5258
53-
:meth:`~.spanner_v1.snapshot.Snapshot.begin` can only be used on a
59+
:meth:`~google.cloud.spanner_v1.snapshot.Snapshot.begin` can only be used on a
5460
snapshot with ``multi_use=True``. In which case it is also necessary
5561
to call if you need to have multiple pending operations.
5662

5763
Read Table Data
5864
---------------
5965

60-
Read data for selected rows from a table in the database. Calls
61-
the ``Read`` API, which returns all rows specified in ``key_set``, or else
62-
fails if the result set is too large,
66+
To read data for selected rows from a table in the database, call
67+
:meth:`~google.cloud.spanner_v1.snapshot.Snapshot.read` which will return
68+
all rows specified in ``key_set``, or fail if the result set is too large,
6369

6470
.. code:: python
6571
@@ -73,16 +79,17 @@ fails if the result set is too large,
7379
7480
.. note::
7581

76-
Perform all iteration within the context of the ``with database.snapshot()``
82+
Perform all iterations within the context of the ``with database.snapshot()``
7783
block.
7884

7985

8086
Execute a SQL Select Statement
8187
------------------------------
8288

83-
Read data from a query against tables in the database. Calls
84-
the ``ExecuteSql`` API, which returns all rows matching the query, or else
85-
fails if the result set is too large,
89+
To read data from tables in the database using a query, call
90+
:meth:`~google.cloud.spanner_v1.snapshot.Snapshot.execute_sql`
91+
which will return all rows matching the query, or fail if the
92+
result set is too large,
8693

8794
.. code:: python
8895

0 commit comments

Comments
 (0)