Skip to content

Commit 662c6a0

Browse files
committed
Adding more documentation
1 parent 85ce40a commit 662c6a0

File tree

4 files changed

+175
-1
lines changed

4 files changed

+175
-1
lines changed

docs/aql.rst

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,155 @@ operations such as creating or deleting :doc:`databases <database>`,
88
information, refer to `ArangoDB manual`_.
99

1010
.. _ArangoDB manual: https://docs.arangodb.com
11+
12+
AQL Queries
13+
===========
14+
15+
AQL queries are invoked from AQL API wrapper. Executing queries returns
16+
:doc:`result cursors <cursor>`.
17+
18+
**Example:**
19+
20+
.. code-block:: python
21+
22+
from arangoasync import ArangoClient, AQLQueryKillError
23+
from arangoasync.auth import Auth
24+
25+
# Initialize the client for ArangoDB.
26+
async with ArangoClient(hosts="http://localhost:8529") as client:
27+
auth = Auth(username="root", password="passwd")
28+
29+
# Connect to "test" database as root user.
30+
db = await client.db("test", auth=auth)
31+
32+
# Get the API wrapper for "students" collection.
33+
students = db.collection("students")
34+
35+
# Insert some test documents into "students" collection.
36+
await students.insert_many([
37+
{"_key": "Abby", "age": 22},
38+
{"_key": "John", "age": 18},
39+
{"_key": "Mary", "age": 21}
40+
])
41+
42+
# Get the AQL API wrapper.
43+
aql = db.aql
44+
45+
# Retrieve the execution plan without running the query.
46+
plan = await aql.explain("FOR doc IN students RETURN doc")
47+
48+
# Validate the query without executing it.
49+
validate = await aql.validate("FOR doc IN students RETURN doc")
50+
51+
# Execute the query
52+
cursor = await db.aql.execute(
53+
"FOR doc IN students FILTER doc.age < @value RETURN doc",
54+
bind_vars={"value": 19}
55+
)
56+
57+
# Iterate through the result cursor
58+
student_keys = []
59+
async for doc in cursor:
60+
student_keys.append(doc)
61+
62+
# List currently running queries.
63+
queries = await aql.queries()
64+
65+
# List any slow queries.
66+
slow_queries = await aql.slow_queries()
67+
68+
# Clear slow AQL queries if any.
69+
await aql.clear_slow_queries()
70+
71+
# Retrieve AQL query tracking properties.
72+
await aql.tracking()
73+
74+
# Configure AQL query tracking properties.
75+
await aql.set_tracking(
76+
max_slow_queries=10,
77+
track_bind_vars=True,
78+
track_slow_queries=True
79+
)
80+
81+
# Kill a running query (this should fail due to invalid ID).
82+
try:
83+
await aql.kill("some_query_id")
84+
except AQLQueryKillError as err:
85+
assert err.http_code == 404
86+
87+
See :class:`arangoasync.aql.AQL` for API specification.
88+
89+
90+
AQL User Functions
91+
==================
92+
93+
**AQL User Functions** are custom functions you define in Javascript to extend
94+
AQL functionality. They are somewhat similar to SQL procedures.
95+
96+
**Example:**
97+
98+
.. code-block:: python
99+
100+
from arangoasync import ArangoClient
101+
from arangoasync.auth import Auth
102+
103+
# Initialize the client for ArangoDB.
104+
async with ArangoClient(hosts="http://localhost:8529") as client:
105+
auth = Auth(username="root", password="passwd")
106+
107+
# Connect to "test" database as root user.
108+
db = await client.db("test", auth=auth)
109+
110+
# Get the AQL API wrapper.
111+
aql = db.aql
112+
113+
# Create a new AQL user function.
114+
await aql.create_function(
115+
# Grouping by name prefix is supported.
116+
name="functions::temperature::converter",
117+
code="function (celsius) { return celsius * 1.8 + 32; }"
118+
)
119+
120+
# List AQL user functions.
121+
functions = await aql.functions()
122+
123+
# Delete an existing AQL user function.
124+
await aql.delete_function("functions::temperature::converter")
125+
126+
See :class:`arangoasync.aql.AQL` for API specification.
127+
128+
129+
AQL Query Cache
130+
===============
131+
132+
**AQL Query Cache** is used to minimize redundant calculation of the same query
133+
results. It is useful when read queries are issued frequently and write queries
134+
are not.
135+
136+
**Example:**
137+
138+
.. code-block:: python
139+
140+
from arangoasync import ArangoClient
141+
from arangoasync.auth import Auth
142+
143+
# Initialize the client for ArangoDB.
144+
async with ArangoClient(hosts="http://localhost:8529") as client:
145+
auth = Auth(username="root", password="passwd")
146+
147+
# Connect to "test" database as root user.
148+
db = await client.db("test", auth=auth)
149+
150+
# Get the AQL API wrapper.
151+
aql = db.aql
152+
153+
# Retrieve AQL query cache properties.
154+
await aql.cache.properties()
155+
156+
# Configure AQL query cache properties
157+
await aql.cache.configure(mode="demand", max_results=10000)
158+
159+
# Clear results in AQL query cache.
160+
await aql.cache.clear()
161+
162+
See :class:`arangoasync.aql.AQLQueryCache` for API specification.

docs/cursor.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Cursors
2+
-------
3+
4+
Many operations provided by python-arango-async (e.g. executing :doc:`aql` queries)
5+
return result **cursors** to batch the network communication between ArangoDB
6+
server and python-arango-async client. Each HTTP request from a cursor fetches the
7+
next batch of results (usually documents). Depending on the query, the total
8+
number of items in the result set may or may not be known in advance.

docs/errors.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,18 @@ Client Errors
1616
=============
1717

1818
:class:`arangoasync.exceptions.ArangoClientError` exceptions originate from
19-
python-arango client itself. They do not contain error codes nor HTTP request
19+
python-arango-async client itself. They do not contain error codes nor HTTP request
2020
response details.
21+
22+
**Example**
23+
24+
.. testcode::
25+
26+
from arangoasync.exceptions import ArangoClientError, ArangoServerError
27+
28+
try:
29+
# Some operation that raises an error
30+
except ArangoClientError:
31+
# An error occurred on the client side
32+
except ArangoServerError:
33+
# An error occurred on the server side

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Miscellaneous
6363
.. toctree::
6464
:maxdepth: 1
6565

66+
cursor
6667
errors
6768
errno
6869

0 commit comments

Comments
 (0)