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

samples: Update the read_time snippet. #363

Merged
merged 4 commits into from Oct 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions samples/snippets/snippets.py
Expand Up @@ -58,18 +58,18 @@ def not_in_query(client):


def query_with_readtime(client):
# [START datastore_snapshot_read]
# Create a read time of 120 seconds in the past
read_time = datetime.now(timezone.utc) - timedelta(seconds=120)
# [START datastore_stale_read]
# Create a read time of 15 seconds in the past
read_time = datetime.now(timezone.utc) - timedelta(seconds=15)

# Fetch an entity at time read_time
# Fetch an entity with read_time
task_key = client.key('Task', 'sampletask')
entity = client.get(task_key, read_time=read_time)

# Query Task entities at time read_time
# Query Task entities with read_time
query = client.query(kind="Task")
tasks = query.fetch(read_time=read_time, limit=10)
# [END datastore_snapshot_read]
# [END datastore_stale_read]

results = list(tasks)
results.append(entity)
Expand Down