- Notifications
You must be signed in to change notification settings - Fork 76
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
Changes from 1 commit
32cdc62 107df52 1149f01 df2ab2f 71776c3 856743a bedc4d4 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -124,3 +124,6 @@ arango/version.py | |
| | ||
| # test results | ||
| *_results.txt | ||
| | ||
| # devcontainers | ||
| .devcontainer | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -126,3 +126,42 @@ def build_filter_conditions(filters: Json) -> str: | |
| conditions.append(f"doc.{field} == {json.dumps(v)}") | ||
| | ||
| return "FILTER " + " AND ".join(conditions) | ||
| | ||
| | ||
| def validate_sort_parameters(sort: Sequence[Json]) -> bool: | ||
| """Validate sort parameters for an AQL query. | ||
| | ||
| :param sort: Document sort parameters. | ||
| :type sort: Sequence[Json] | ||
| :return: Validation success. | ||
| :rtype: bool | ||
| :raise arango.exceptions.DocumentGetError: 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( | ||
| "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'") | ||
| return True | ||
| | ||
| | ||
| def build_sort_expression(sort: Sequence[Json]) -> str: | ||
apetenchea marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| """Build a sort condition for an AQL query. | ||
| | ||
| :param sort: Document sort parameters. | ||
| :type sort: Sequence[Json] | ||
| :return: The complete AQL sort condition. | ||
| :rtype: str | ||
| """ | ||
| if not sort: | ||
| return "" | ||
| | ||
| sort_chunks = [] | ||
| for sort_param in sort: | ||
| chunk = f"doc.{sort_param['sort_by']} {sort_param['sort_order']}" | ||
| sort_chunks.append(chunk) | ||
| | ||
| return "SORT " + ", ".join(sort_chunks) | ||
Uh oh!
There was an error while loading. Please reload this page.