Skip to content

Commit f51d17a

Browse files
authored
Adding more REST methods (#29)
* Improving REST API coverage * Fixing cluster-only properties * Fixing enterprise-only features
1 parent 0e72920 commit f51d17a

File tree

10 files changed

+969
-32
lines changed

10 files changed

+969
-32
lines changed

arangoasync/collection.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
HTTP_PRECONDITION_FAILED,
1010
)
1111
from arangoasync.exceptions import (
12+
CollectionPropertiesError,
1213
DocumentGetError,
1314
DocumentInsertError,
1415
DocumentParseError,
@@ -18,7 +19,7 @@
1819
from arangoasync.request import Method, Request
1920
from arangoasync.response import Response
2021
from arangoasync.serialization import Deserializer, Serializer
21-
from arangoasync.typings import Json, Params, Result
22+
from arangoasync.typings import CollectionProperties, Json, Params, Result
2223

2324
T = TypeVar("T")
2425
U = TypeVar("U")
@@ -48,9 +49,6 @@ def __init__(
4849
self._doc_deserializer = doc_deserializer
4950
self._id_prefix = f"{self._name}/"
5051

51-
def __repr__(self) -> str:
52-
return f"<StandardCollection {self.name}>"
53-
5452
def _validate_id(self, doc_id: str) -> str:
5553
"""Check the collection name in the document ID.
5654
@@ -148,6 +146,15 @@ def name(self) -> str:
148146
"""
149147
return self._name
150148

149+
@property
150+
def db_name(self) -> str:
151+
"""Return the name of the current database.
152+
153+
Returns:
154+
str: Database name.
155+
"""
156+
return self._executor.db_name
157+
151158

152159
class StandardCollection(Collection[T, U, V]):
153160
"""Standard collection API wrapper.
@@ -168,6 +175,33 @@ def __init__(
168175
) -> None:
169176
super().__init__(executor, name, doc_serializer, doc_deserializer)
170177

178+
def __repr__(self) -> str:
179+
return f"<StandardCollection {self.name}>"
180+
181+
async def properties(self) -> Result[CollectionProperties]:
182+
"""Return the full properties of the current collection.
183+
184+
Returns:
185+
CollectionProperties: Properties.
186+
187+
Raises:
188+
CollectionPropertiesError: If retrieval fails.
189+
190+
References:
191+
- `get-the-properties-of-a-collection <https://docs.arangodb.com/stable/develop/http-api/collections/#get-the-properties-of-a-collection>`__
192+
""" # noqa: E501
193+
request = Request(
194+
method=Method.GET,
195+
endpoint=f"/_api/collection/{self.name}/properties",
196+
)
197+
198+
def response_handler(resp: Response) -> CollectionProperties:
199+
if not resp.is_success:
200+
raise CollectionPropertiesError(resp, request)
201+
return CollectionProperties(self._executor.deserialize(resp.raw_body))
202+
203+
return await self._executor.execute(request, response_handler)
204+
171205
async def get(
172206
self,
173207
document: str | Json,
@@ -269,6 +303,9 @@ async def insert(
269303
bool | dict: Document metadata (e.g. document id, key, revision) or `True`
270304
if **silent** is set to `True`.
271305
306+
Raises:
307+
DocumentInsertError: If insertion fails.
308+
272309
References:
273310
- `create-a-document <https://docs.arangodb.com/stable/develop/http-api/documents/#create-a-document>`__
274311
""" # noqa: E501

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy