Skip to content

Commit 626adca

Browse files
committed
Merge pull request #489 from tseaver/466-query-keys_only
Add 'keys_only' method to Query.
2 parents aafa7ae + 0c5cef5 commit 626adca

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

gcloud/datastore/query.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ def projection(self, projection):
246246
projection = [projection]
247247
self._projection[:] = projection
248248

249+
def keys_only(self):
250+
"""Set the projection to include only keys."""
251+
self._projection[:] = ['__key__']
252+
249253
@property
250254
def order(self):
251255
"""Names of fields used to sort query results.

gcloud/datastore/test_query.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ def test_projection_setter_multiple_calls(self):
250250
query.projection = _PROJECTION2
251251
self.assertEqual(query.projection, _PROJECTION2)
252252

253+
def test_keys_only(self):
254+
_KIND = 'KIND'
255+
query = self._makeOne(_KIND)
256+
query.keys_only()
257+
self.assertEqual(query.projection, ['__key__'])
258+
253259
def test_order_setter_empty(self):
254260
_KIND = 'KIND'
255261
query = self._makeOne(_KIND, order=['foo', '-bar'])

0 commit comments

Comments
 (0)