9
9
HTTP_PRECONDITION_FAILED ,
10
10
)
11
11
from arangoasync .exceptions import (
12
+ CollectionPropertiesError ,
12
13
DocumentGetError ,
13
14
DocumentInsertError ,
14
15
DocumentParseError ,
18
19
from arangoasync .request import Method , Request
19
20
from arangoasync .response import Response
20
21
from arangoasync .serialization import Deserializer , Serializer
21
- from arangoasync .typings import Json , Params , Result
22
+ from arangoasync .typings import CollectionProperties , Json , Params , Result
22
23
23
24
T = TypeVar ("T" )
24
25
U = TypeVar ("U" )
@@ -48,9 +49,6 @@ def __init__(
48
49
self ._doc_deserializer = doc_deserializer
49
50
self ._id_prefix = f"{ self ._name } /"
50
51
51
- def __repr__ (self ) -> str :
52
- return f"<StandardCollection { self .name } >"
53
-
54
52
def _validate_id (self , doc_id : str ) -> str :
55
53
"""Check the collection name in the document ID.
56
54
@@ -148,6 +146,15 @@ def name(self) -> str:
148
146
"""
149
147
return self ._name
150
148
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
+
151
158
152
159
class StandardCollection (Collection [T , U , V ]):
153
160
"""Standard collection API wrapper.
@@ -168,6 +175,33 @@ def __init__(
168
175
) -> None :
169
176
super ().__init__ (executor , name , doc_serializer , doc_deserializer )
170
177
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
+
171
205
async def get (
172
206
self ,
173
207
document : str | Json ,
@@ -269,6 +303,9 @@ async def insert(
269
303
bool | dict: Document metadata (e.g. document id, key, revision) or `True`
270
304
if **silent** is set to `True`.
271
305
306
+ Raises:
307
+ DocumentInsertError: If insertion fails.
308
+
272
309
References:
273
310
- `create-a-document <https://docs.arangodb.com/stable/develop/http-api/documents/#create-a-document>`__
274
311
""" # noqa: E501
0 commit comments