Skip to content

Commit

Permalink
✨ add order_by and descending options to python Scan object
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Jul 26, 2024
1 parent 1dadd5a commit a38d6dc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
6 changes: 5 additions & 1 deletion wrappers/python/aries_askar/bindings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,21 @@ async def scan_start(
tag_filter: Optional[Union[str, dict]] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
order_by: Optional[str] = None,
descending: bool = False,
) -> ScanHandle:
"""Create a new Scan against the Store."""
return await invoke_async(
"askar_scan_start",
(StoreHandle, FfiStr, FfiStr, FfiJson, c_int64, c_int64),
(StoreHandle, FfiStr, FfiStr, FfiJson, c_int64, c_int64, FfiStr, c_int8),
handle,
profile,
category,
tag_filter,
offset or 0,
limit if limit is not None else -1,
order_by,
descending,
return_type=ScanHandle,
)

Expand Down
39 changes: 35 additions & 4 deletions wrappers/python/aries_askar/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,20 @@ def __init__(
tag_filter: Union[str, dict] = None,
offset: int = None,
limit: int = None,
order_by: Optional[str] = None,
descending: bool = False,
):
"""Initialize the Scan instance."""
self._params = (store, profile, category, tag_filter, offset, limit)
self._params = (
store,
profile,
category,
tag_filter,
offset,
limit,
order_by,
descending,
)
self._handle: ScanHandle = None
self._buffer: IterEntryList = None

Expand All @@ -265,14 +276,30 @@ def __aiter__(self):
async def __anext__(self):
"""Fetch the next scan result during async iteration."""
if self._handle is None:
(store, profile, category, tag_filter, offset, limit) = self._params
(
store,
profile,
category,
tag_filter,
offset,
limit,
order_by,
descending,
) = self._params
self._params = None
if not store.handle:
raise AskarError(
AskarErrorCode.WRAPPER, "Cannot scan from closed store"
)
self._handle = await bindings.scan_start(
store.handle, profile, category, tag_filter, offset, limit
store.handle,
profile,
category,
tag_filter,
offset,
limit,
order_by,
descending,
)
list_handle = await bindings.scan_next(self._handle)
self._buffer = iter(EntryList(list_handle)) if list_handle else None
Expand Down Expand Up @@ -428,9 +455,13 @@ def scan(
offset: int = None,
limit: int = None,
profile: str = None,
order_by: Optional[str] = None,
descending: bool = False,
) -> Scan:
"""Start a new record scan."""
return Scan(self, profile, category, tag_filter, offset, limit)
return Scan(
self, profile, category, tag_filter, offset, limit, order_by, descending
)

def session(self, profile: str = None) -> "OpenSession":
"""Open a new session on the store without starting a transaction."""
Expand Down

0 comments on commit a38d6dc

Please sign in to comment.