Skip to content

Commit 1dd2074

Browse files
authored
Adding custom requests (#67)
1 parent e5a2128 commit 1dd2074

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

arangoasync/database.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,21 @@ def response_handler(resp: Response) -> Any:
28612861

28622862
return await self._executor.execute(request, response_handler)
28632863

2864+
async def request(self, request: Request) -> Result[Response]:
2865+
"""Execute a custom request.
2866+
2867+
Args:
2868+
request (Request): Request object to be executed.
2869+
2870+
Returns:
2871+
Response: Response object containing the result of the request.
2872+
"""
2873+
2874+
def response_handler(resp: Response) -> Response:
2875+
return resp
2876+
2877+
return await self._executor.execute(request, response_handler)
2878+
28642879

28652880
class StandardDatabase(Database):
28662881
"""Standard database API wrapper.

docs/database.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ information.
1414
1515
from arangoasync import ArangoClient
1616
from arangoasync.auth import Auth
17+
from arangoasync.request import Method, Request
1718
1819
# Initialize the client for ArangoDB.
1920
async with ArangoClient(hosts="http://localhost:8529") as client:
@@ -60,4 +61,10 @@ information.
6061
# Delete the database. Note that the new users will remain.
6162
await sys_db.delete_database("test")
6263
64+
# Example of a custom request
65+
request = Request(
66+
method=Method.POST, endpoint="/_admin/execute", data="return 1".encode("utf-8")
67+
)
68+
response = await sys_db.request(request)
69+
6370
See :class:`arangoasync.client.ArangoClient` and :class:`arangoasync.database.StandardDatabase` for API specification.

tests/test_database.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import datetime
3+
import json
34

45
import pytest
56
from packaging import version
@@ -36,6 +37,7 @@
3637
ServerTimeError,
3738
ServerVersionError,
3839
)
40+
from arangoasync.request import Method, Request
3941
from arangoasync.typings import CollectionType, KeyOptions, UserInfo
4042
from tests.helpers import generate_col_name, generate_db_name, generate_username
4143

@@ -157,6 +159,13 @@ async def test_database_misc_methods(
157159
)
158160
await db.compact()
159161

162+
# Custom Request
163+
request = Request(
164+
method=Method.POST, endpoint="/_admin/execute", data="return 1".encode("utf-8")
165+
)
166+
response = await sys_db.request(request)
167+
assert json.loads(response.raw_body) == 1
168+
160169

161170
@pytest.mark.asyncio
162171
async def test_create_drop_database(

0 commit comments

Comments
 (0)