Skip to content

Commit

Permalink
add cursor support
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemia committed Aug 26, 2014
1 parent af92e74 commit 25672e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def run_query(self, dataset_id, query_pb, namespace=None):

request.query.CopyFrom(query_pb)
response = self._rpc(dataset_id, 'runQuery', request, datastore_pb.RunQueryResponse)
return [e.entity for e in response.batch.entity_result]
return ([e.entity for e in response.batch.entity_result], response.batch.end_cursor, response.batch.more_results, response.batch.skipped_results)

def lookup(self, dataset_id, key_pbs):
"""Lookup keys from a dataset in the Cloud Datastore.
Expand Down
13 changes: 12 additions & 1 deletion gcloud/datastore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,19 @@ def fetch(self, limit=None):
if limit:
clone = self.limit(limit)

entity_pbs = self.dataset().connection().run_query(
entity_pbs, end_cursor, more_results, skipped_results = self.dataset().connection().run_query(
query_pb=clone.to_protobuf(), dataset_id=self.dataset().id())

self._cursor = end_cursor
return [Entity.from_protobuf(entity, dataset=self.dataset())
for entity in entity_pbs]

def cursor(self):
return self._cursor

def with_cursor(self, start_cursor, end_cursor=None):
if start_cursor:
self._pb.start_cursor = start_cursor
if end_cursor:
self._pb.end_cursor = end_cursor

0 comments on commit 25672e1

Please sign in to comment.