Skip to main content

ArangoDB AQL builder

Project description

pipeline status coverage report Latest Release Python version ArangoDB version

ArangoDB AQL builder

Python AQL builder for ArangoDB, a scalable multi-model database natively supporting documents, graphs and search.

Requirements

  • Python version 3.7+

Installation

pip install aql-builder --upgrade

Getting Started

Here are simple usage examples:

>>> from aql_builder import AQLBuilder as AB
>>> 
>>> AB.for_('my').in_('mycollection').return_('my._key').to_aql()
'FOR my IN mycollection RETURN my._key'
>>> 
>>> AB.for_('u').in_('users').replace('u').in_('backup').to_aql()
'FOR u IN users REPLACE u IN backup'
>>> 
>>> AB.for_('u').in_('users')
...     .filter(
...         AB.ref('u.active').eq(True)
...         .and_(AB.ref('u.age').gte(35))
...         .and_(AB.ref('u.age').lte(37))
...     )
...     .remove('u').in_('users')
...     .to_aql()
'FOR u IN users FILTER (((u.active == true) && (u.age >= 35)) && (u.age <= 37)) REMOVE u IN users'
>>> 

Working with query parameters:

>>> from aql_builder import AQLBuilder as AB
>>> 
>>> AB.for_('user').in_('@@users').filter(AB.ref('user.age').gte('@min_age')).return_('user._key').to_aql()
'FOR user IN @@users FILTER (user.age >= @min_age) RETURN user._key'
>>> 

Working with graph:

>>> from aql_builder import AQLBuilder as AB
>>> 
>>> AB.for_('v').in_graph(
...         graph='knowsGraph',
...         direction='OUTBOUND',
...         start_vertex=AB.str('users/1'),
...         min_depth=1,
...         max_depth=3
...     )
...     .return_('v._key')
...     .to_aql()
'FOR v IN 1..3 OUTBOUND "users/1" GRAPH "knowsGraph" RETURN v._key'
>>> 

More complex examples:

>>> from aql_builder import AQLBuilder as AB
>>> 
>>> AB.for_('i').in_(AB.range(1, 1000))
...     .insert({
...         'id': AB(100000).add('i'),
...         'age': AB(18).add(AB.FLOOR(AB.RAND().times(25))),
...         'name': AB.CONCAT('test', AB.TO_STRING('i')),
...         'active': False,
...         'gender': (
...             AB.ref('i').mod(2).eq(0).then('"male"').else_('"female"')
...         )
...     }).into('users')
...     .to_aql()
'FOR i IN 1..1000 INSERT '
'{"id": (100000 + i), '
'"age": (18 + FLOOR((RAND() * 25))), '
'"name": CONCAT(test, TO_STRING(i)), '
'"active": false, '
'"gender": (((i % 2) == 0) ? "male" : "female")} '
'INTO users'
>>> 
>>> 
>>> AB.for_('u').in_('users')
...     .filter(AB.ref('u.active').eq(True))
...     .collect({
...         'ageGroup': AB.FLOOR(AB.ref('u.age').div(5)).times(5),
...         'gender': 'u.gender'
...     }).into('group')
...     .sort('ageGroup', 'DESC')
...     .return_({
...         'ageGroup': 'ageGroup',
...         'gender': 'gender'
...     })
...     .to_aql()
'FOR u IN users '
'FILTER (u.active == true) '
'COLLECT ageGroup = (FLOOR((u.age / 5)) * 5), gender = u.gender INTO group '
'SORT ageGroup DESC '
'RETURN {"ageGroup": ageGroup, "gender": gender}'
>>> 

Acknowledgements

AQL builder is a free software project hosted at https://foss.heptapod.net. Thanks to the support of Clever Cloud, Octobus and the sponsors of the heptapod project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aql-builder-0.0.13.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

aql_builder-0.0.13-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file aql-builder-0.0.13.tar.gz.

File metadata

  • Download URL: aql-builder-0.0.13.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for aql-builder-0.0.13.tar.gz
Algorithm Hash digest
SHA256 edb0564e3cbd4f41e6196def4a9ab3f618579a87abadb74f1e4f21015e0183dc
MD5 9ccd2971dd36ab1e1f9763fd5a287085
BLAKE2b-256 6065c65452f59679d7b0e514268fefe3d07ab6af5001e8c38139316654d41f99

See more details on using hashes here.

File details

Details for the file aql_builder-0.0.13-py3-none-any.whl.

File metadata

File hashes

Hashes for aql_builder-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 2365e661d3ec84902dd29573067f3ce6499ab38f71aadd5c6de99db01fdfab8c
MD5 9bf8d648c25daf532b7d58d1f7dfca15
BLAKE2b-256 11e1958641a17801d86bcde27a5ac1a6a3fabaab25486d4863c2783f0394e850

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page