Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Spanner README. #3796

Merged
merged 1 commit into from
Aug 11, 2017
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
19 changes: 13 additions & 6 deletions spanner/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,27 @@ as a callback to ``database.run_in_transaction``:
# The use of @parameters is recommended rather than doing your
# own string interpolation; this provides protections against
# SQL injection attacks.
query = """UPDATE people
SET anniversary = @uxts
query = """SELECT anniversary FROM people
WHERE id = @person_id"""

# When executing the SQL statement, the query and parameters are sent
# as separate arguments. When using parameters, you must specify
# both the parameters themselves and their types.
transaction.execute_sql(
row = transaction.execute_sql(
query=query,
params={'person_id': person_id, 'uxts': unix_timestamp},
params={'person_id': person_id},
param_types={
'person_id': types.INT64_PARAM_TYPE,
'uxts': types.INT64_PARAM_TYPE,
},
).one()

# Now perform an update on the data.
old_anniversary = row[0]
new_anniversary = _compute_anniversary(old_anniversary, years)
transaction.update(
'people',
['person_id', 'anniversary'],
[person_id, new_anniversary],
)

# Actually run the `update_anniversary` function in a transaction.
Expand Down Expand Up @@ -140,4 +147,4 @@ Learn More
See the ``google-cloud-python`` API `Cloud Spanner documentation`_ to learn how
to connect to Cloud Spanner using this Client Library.

.. _Cloud Spanner documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/usage.html
.. _Cloud Spanner documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/spanner/usage.html