Now it’s possible to querieng database by using Arango Query Language (AQL).
This functionality implementation based on HTTP Interface for AQL Query Cursors and provide lazy iterator over dataset and with ability to customize (wrap) result item by custom wrapper.
Alternative way to do such king of functionality is by using Documents REST Api which is not implemented in driver.
Work with Cursors in ArangoDB. At the moment, it’s common routine to work with AQL from this driver.
Note
the server will also destroy abandoned cursors automatically after a certain server-controlled timeout to avoid resource leakage.
query - contains the query string to be executed (mandatory)
number of documents found should be returned as “count” attribute in the result set (optional). Calculating the “count” attribute might have a performance penalty for some queries so this option is turned off by default.
transferred from the server to the client in one roundtrip (optional). If this attribute is not set, a server-controlled default value will be used.
bindVars - key/value list of bind parameters (optional).
class, wrap result into
It’s not necessary to wrap all documents within Document object. Cursor do it by default but you can provide custom wrapper by overriding wrapper argument during execution of connection.query method.
wrapper should accept two arguments:
- connection - first argument, current connection instnace
- item - dictionary with data provided from ArangoDB query
from arango import c
wrapper = lambda conn, item: item
c.collection.test.create()
c.collection.test.documents.create({"1": 2})
# create connection to database
for item in c.query("FOR d in test RETURN d", wrapper=wrapper):
print item