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.15.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aql_builder-0.0.15-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file aql_builder-0.0.15.tar.gz.

File metadata

  • Download URL: aql_builder-0.0.15.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for aql_builder-0.0.15.tar.gz
Algorithm Hash digest
SHA256 443f376849ca60e15033787251f7bb296bdc6bfb70f4a5d86b7ebb0b1228369e
MD5 16d78876eeeee83cf9a67319bc3a1694
BLAKE2b-256 962491bbddca2c4d35d7aff561fc51a37443b18ab5f1aaa33304336ae30553ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aql_builder-0.0.15-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for aql_builder-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 6f0aab6b5c835a657b21331884b8eb5407bf8250d8096761ec2094744c22896b
MD5 5d1b8a6ee905ad55f39702d532c02da7
BLAKE2b-256 e15406fea0ba587bf02db378b7ee6cd538cea8acf41032d399999c4218029a2f

See more details on using hashes here.

Supported by

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