8000 add support for sort in collection.find function by denizalpaslan · Pull Request #359 · arangodb/python-arango · GitHub
[go: up one dir, main page]

Skip to content

add support for sort in collection.find function #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arango/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ def find(
:return: Document cursor.
:rtype: arango.cursor.Cursor
:raise arango.exceptions.DocumentGetError: If retrieval fails.
:raise arango.exceptions.SortValidationError: If sort parameters are invalid.
"""
assert isinstance(filters, dict), "filters must be a dict"
assert is_none_or_int(skip), "skip must be a non-negative int"
Expand Down
8 changes: 4 additions & 4 deletions arango/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from contextlib import contextmanager
from typing import Any, Iterator, Sequence, Union

from arango.exceptions import DocumentParseError
from arango.exceptions import DocumentParseError, SortValidationError
from arango.typings import Json, Jsons


Expand Down Expand Up @@ -135,16 +135,16 @@ def validate_sort_parameters(sort: Sequence[Json]) -> bool:
:type sort: Sequence[Json]
:return: Validation success.
:rtype: bool
:raise arango.exceptions.DocumentGetError: If sort parameters are invalid.
:raise arango.exceptions.SortValidationError: If sort parameters are invalid.
"""
assert isinstance(sort, Sequence)
for param in sort:
if "sort_by" not in param or "sort_order" not in param:
raise DocumentParseError(
raise SortValidationError(
"Each sort parameter must have 'sort_by' and 'sort_order'."
)
if param["sort_order"].upper() not in ["ASC", "DESC"]:
raise DocumentParseError("'sort_order' must be either 'ASC' or 'DESC'")
raise SortValidationError("'sort_order' must be either 'ASC' or 'DESC'")
return True


Expand Down
0