Skip to content

Commit 5235b8e

Browse files
author
Jeroen van der Heijden
committed
limit and offset support to get_entities_by_kind(), issue #30
1 parent 03bc7bc commit 5235b8e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

aiogcd/connector/connector.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,25 @@ async def get_key(self, data):
310310
result = await self.get_keys(data)
311311
return result[0] if result else None
312312

313-
async def get_entities_by_kind(self, kind):
313+
async def get_entities_by_kind(self, kind, offset=None, limit=None,
314+
cursor=None):
314315
"""Returns entities by kind.
315316
316-
This is a shortcut for:
317-
get_entities({'query': {'kind': [{'name': kind}]}})
317+
When a limit is set, this function returns a list and a cursor.
318+
If no limit is used, then only the list will be returned.
318319
"""
319-
data = {'query': {'kind': [{'name': kind}]}}
320-
return await self.get_entities(data)
320+
query = {'kind': [{'name': kind}]}
321+
data = {'query': query}
322+
if cursor:
323+
query['startCursor'] = cursor
324+
if offset:
325+
query['offset'] = offset
326+
327+
if limit is None:
328+
return await self.get_entities(data)
329+
else:
330+
query['limit'] = limit
331+
return await self._get_entities_cursor(data)
321332

322333
async def get_entities_by_keys(self, keys, missing=None, deferred=None,
323334
eventual=False):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import setuptools
1616
from distutils.core import setup, Extension
1717

18-
VERSION = '0.11.13'
18+
VERSION = '0.11.14'
1919

2020
install_requires = [
2121
'aiohttp>=2',

0 commit comments

Comments
 (0)