Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 745ac26

Browse filesBrowse files
authored
[Firebase] Add snapshot cursors sample (GoogleCloudPlatform#1780)
* Add snapshot cursors sample * Updating sample with a test
1 parent 0a9f0fb commit 745ac26
Copy full SHA for 745ac26

File tree

Expand file treeCollapse file tree

2 files changed

+24
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-0
lines changed

‎firestore/cloud-client/snippets.py

Copy file name to clipboardExpand all lines: firestore/cloud-client/snippets.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,22 @@ def cursor_simple_end_at():
557557
return query_end_at
558558

559559

560+
def snapshot_cursors():
561+
db = firestore.Client()
562+
# [START fs_start_at_snapshot_query_cursor]
563+
doc_ref = db.collection(u'cities').document(u'SF')
564+
565+
snapshot = doc_ref.get()
566+
start_at_snapshot = db.collection(
567+
u'cities').order_by(u'population').start_at(snapshot)
568+
# [END fs_start_at_snapshot_query_cursor]
569+
results = start_at_snapshot.limit(10).get()
570+
for doc in results:
571+
print('{}'.format(doc.id))
572+
573+
return results
574+
575+
560576
def cursor_paginate():
561577
db = firestore.Client()
562578
# [START cursor_paginate]

‎firestore/cloud-client/snippets_test.py

Copy file name to clipboardExpand all lines: firestore/cloud-client/snippets_test.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ def test_cursor_simple_end_at():
195195
snippets.cursor_simple_end_at()
196196

197197

198+
def test_snapshot_cursors(capsys):
199+
snippets.snapshot_cursors()
200+
out, _ = capsys.readouterr()
201+
assert "SF" in out
202+
assert "TOK" in out
203+
assert "BJ" in out
204+
205+
198206
def test_cursor_paginate():
199207
snippets.cursor_paginate()
200208

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.