8000 [Firebase] Add snapshot cursors sample by frankyn · Pull Request #1780 · GoogleCloudPlatform/python-docs-samples · GitHub
[go: up one dir, main page]

Skip to content

[Firebase] Add snapshot cursors sample #1780

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

Merged
merged 6 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions firestore/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,22 @@ def cursor_simple_end_at():
return query_end_at


def snapshot_cursors():
db = firestore.Client()
# [START fs_start_at_snapshot_query_cursor]
doc_ref = db.collection(u'cities').document(u'SF')

snapshot = doc_ref.get()
start_at_snapshot = db.collection(
u'cities').order_by(u'population').start_at(snapshot)
# [END fs_start_at_snapshot_query_cursor]
results = start_at_snapshot.limit(10).get()
for doc in results:
print('{}'.format(doc.id))

return results


def cursor_paginate():
db = firestore.Client()
# [START cursor_paginate]
Expand Down
8 changes: 8 additions & 0 deletions firestore/cloud-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ def test_cursor_simple_end_at():
snippets.cursor_simple_end_at()


def test_snapshot_cursors(capsys):
snippets.snapshot_cursors()
out, _ = capsys.readouterr()
assert "SF" in out
assert "TOK" in out
assert "BJ" in out


def test_cursor_paginate():
snippets.cursor_paginate()

Expand Down
0