|
1 | 1 | __all__ = ["Collection", "StandardCollection"]
|
2 | 2 |
|
3 | 3 |
|
4 |
| -from typing import Generic, List, Optional, Tuple, TypeVar, cast |
| 4 | +from typing import Generic, List, Optional, Sequence, Tuple, TypeVar, cast |
5 | 5 |
|
6 | 6 | from arangoasync.errno import (
|
7 | 7 | DOCUMENT_NOT_FOUND,
|
@@ -889,3 +889,55 @@ def response_handler(resp: Response) -> bool | Json:
|
889 | 889 | raise DocumentDeleteError(resp, request, msg)
|
890 | 890 |
|
891 | 891 | return await self._executor.execute(request, response_handler)
|
| 892 | + |
| 893 | + async def get_many( |
| 894 | + self, |
| 895 | + documents: Sequence[str | Json], |
| 896 | + allow_dirty_read: Optional[bool] = None, |
| 897 | + ignore_revs: Optional[bool] = None, |
| 898 | + ) -> Result[V]: |
| 899 | + """Return multiple documents ignoring any missing ones. |
| 900 | +
|
| 901 | + Args: |
| 902 | + documents (list): List of document IDs, keys or bodies. A search document |
| 903 | + must contain at least a value for the `_key` field. A value for `_rev` |
| 904 | + may be specified to verify whether the document has the same revision |
| 905 | + value, unless `ignoreRevs` is set to false. |
| 906 | + allow_dirty_read (bool | None): Allow reads from followers in a cluster. |
| 907 | + ignore_revs (bool | None): If set to `True`, the `_rev` attribute in the |
| 908 | + document is ignored. If this is set to `False`, then the `_rev` |
| 909 | + attribute given in the body document is taken as a precondition. |
| 910 | + The document is only replaced if the current revision is the one |
| 911 | + specified. |
| 912 | +
|
| 913 | + Returns: |
| 914 | + list: List of documents. Missing ones are not included. |
| 915 | +
|
| 916 | + Raises: |
| 917 | + DocumentGetError: If retrieval fails. |
| 918 | +
|
| 919 | + References: |
| 920 | + - `get-multiple-documents <https://docs.arangodb.com/stable/develop/http-api/documents/#get-multiple-documents>`__ |
| 921 | + """ # noqa: E501 |
| 922 | + params: Params = {"onlyget": True} |
| 923 | + if ignore_revs is not None: |
| 924 | + params["ignoreRevs"] = ignore_revs |
| 925 | + |
| 926 | + headers: RequestHeaders = {} |
| 927 | + if allow_dirty_read is not None: |
| 928 | + headers["x-arango-allow-dirty-read"] = allow_dirty_read |
| 929 | + |
| 930 | + request = Request( |
| 931 | + method=Method.PUT, |
| 932 | + endpoint=f"/_api/document/{self.name}", |
| 933 | + params=params, |
| 934 | + headers=headers, |
| 935 | + data=self.serializer.dumps(documents), |
| 936 | + ) |
| 937 | + |
| 938 | + def response_handler(resp: Response) -> V: |
| 939 | + if not resp.is_success: |
| 940 | + raise DocumentGetError(resp, request) |
| 941 | + return self._doc_deserializer.loads_many(resp.raw_body) |
| 942 | + |
| 943 | + return await self._executor.execute(request, response_handler) |
0 commit comments