Skip to content

Commit

Permalink
Revamp the library for 5.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
joowani committed Aug 22, 2019
1 parent 8199148 commit 20118b9
Show file tree
Hide file tree
Showing 65 changed files with 2,121 additions and 2,125 deletions.
22 changes: 15 additions & 7 deletions .travis.yml
@@ -1,17 +1,25 @@
sudo: false
language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
matrix:
include:
- python: 2.7
- python: 3.4
- python: 3.5
- python: 3.6
- python: 3.7
dist: xenial
sudo: true
services:
- docker
before_install:
- docker run --name arango -d -p 8529:8529 -e ARANGO_ROOT_PASSWORD=passwd arangodb/arangodb:3.4.0
- docker run --name arango -d -p 8529:8529 -e ARANGO_ROOT_PASSWORD=passwd arangodb/arangodb:3.5.0
- docker cp tests/static/service.zip arango:/tmp/service.zip
install:
- pip install flake8 mock pytest pytest-cov python-coveralls sphinx sphinx_rtd_theme
- pip install flake8 mock
- pip install pytest==3.5.1
- pip install pytest-cov==2.5.1
- pip install python-coveralls==2.9.1
- pip install sphinx sphinx_rtd_theme
- pip install .
script:
- python -m flake8
Expand Down
30 changes: 16 additions & 14 deletions README.rst
Expand Up @@ -22,11 +22,11 @@
:target: https://coveralls.io/github/joowani/python-arango?branch=master
:alt: Test Coverage

.. image:: https://img.shields.io/github/issues/joowani/python-arango.svg
.. image:: https://img.shields.io/github/issues/joowani/python-arango.svg
:target: https://github.com/joowani/python-arango/issues
:alt: Issues Open

.. image:: https://img.shields.io/badge/license-MIT-blue.svg
.. image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://raw.githubusercontent.com/joowani/python-arango/master/LICENSE
:alt: MIT License

Expand All @@ -37,23 +37,25 @@ Welcome to the GitHub page for **python-arango**, a Python driver for ArangoDB_.
Announcements
=============

- Python-arango version `4.0.0`_ is now out!
- Please see the releases_ page for latest updates.
- Python-arango version `5.0.0`_ is finally up! This release supports ArangoDB
version 3.5+ only. It also breaks backward-compatibility and you must make
changes in your application code. Please see the releases_ page for details.

Features
========

- Clean Pythonic interface.
- Lightweight.
- High ArangoDB REST API coverage.
- Pythonic interface
- Lightweight
- High API coverage

Compatibility
=============

- Python versions 2.7, 3.4, 3.5 and 3.6 are supported.
- Python-arango 4.x supports ArangoDB 3.3+ (recommended).
- Python-arango 3.x supports ArangoDB 3.0 ~ 3.2 only.
- Python-arango 2.x supports ArangoDB 1.x ~ 2.x only.
- Python versions 2.7, 3.4, 3.5, 3.6 and 3.7 are supported
- Python-arango 5.x supports ArangoDB 3.5+
- Python-arango 4.x supports ArangoDB 3.3 ~ 3.4 only
- Python-arango 3.x supports ArangoDB 3.0 ~ 3.2 only
- Python-arango 2.x supports ArangoDB 1.x ~ 2.x only

Installation
============
Expand Down Expand Up @@ -83,7 +85,7 @@ Here is a simple usage example:
from arango import ArangoClient
# Initialize the client for ArangoDB.
client = ArangoClient(protocol='http', host='localhost', port=8529)
client = ArangoClient(hosts='http://localhost:8529')
# Connect to "_system" database as root user.
sys_db = client.db('_system', username='root', password='passwd')
Expand Down Expand Up @@ -117,7 +119,7 @@ Here is another example with graphs:
from arango import ArangoClient
# Initialize the client for ArangoDB.
client = ArangoClient(protocol='http', host='localhost', port=8529)
client = ArangoClient(hosts='http://localhost:8529')
# Connect to "test" database as root user.
db = client.db('test', username='root', password='passwd')
Expand Down Expand Up @@ -169,7 +171,7 @@ Contributing
Please take a look at this page_ before submitting a pull request. Thanks!

.. _ArangoDB: https://www.arangodb.com
.. _4.0.0: https://github.com/joowani/python-arango/releases/tag/4.0.0
.. _5.0.0: https://github.com/joowani/python-arango/releases/tag/5.0.0
.. _releases: https://github.com/joowani/python-arango/releases
.. _PyPi: https://pypi.python.org/pypi/python-arango
.. _GitHub: https://github.com/joowani/python-arango
Expand Down
1 change: 0 additions & 1 deletion arango/api.py
Expand Up @@ -15,7 +15,6 @@ class APIWrapper(object):
def __init__(self, connection, executor):
self._conn = connection
self._executor = executor
self._is_transaction = self.context == 'transaction'

@property
def db_name(self):
Expand Down
83 changes: 55 additions & 28 deletions arango/aql.py
@@ -1,7 +1,5 @@
from __future__ import absolute_import, unicode_literals

from json import dumps

__all__ = ['AQL', 'AQLQueryCache']

from arango.api import APIWrapper
Expand Down Expand Up @@ -42,7 +40,7 @@ def __repr__(self):
return '<AQL in {}>'.format(self._conn.db_name)

# noinspection PyMethodMayBeStatic
def _format_tracking(self, body):
def _format_tracking_properties(self, body):
"""Format the tracking properties.
:param body: Response body.
Expand Down Expand Up @@ -237,10 +235,10 @@ def execute(self,
enterprise version of ArangoDB.
:type satellite_sync_wait: int | float
:param read_collections: Names of collections read during query
execution. Required for :doc:`transactions <transaction>`.
execution. This parameter is deprecated.
:type read_collections: [str | unicode]
:param write_collections: Names of collections written to during query
execution. Required for :doc:`transactions <transaction>`.
execution. This parameter is deprecated.
:type write_collections: [str | unicode]
:param stream: If set to True, query is executed in streaming fashion:
query result is not stored server-side but calculated on the fly.
Expand Down Expand Up @@ -310,17 +308,10 @@ def execute(self,
data['options'] = options
data.update(options)

command = 'db._query({}, {}, {}).toArray()'.format(
dumps(query),
dumps(bind_vars),
dumps(data),
) if self._is_transaction else None

request = Request(
method='post',
endpoint='/_api/cursor',
data=data,
command=command,
read=read_collections,
write=write_collections
)
Expand Down Expand Up @@ -425,7 +416,7 @@ def tracking(self):
def response_handler(resp):
if not resp.is_success:
raise AQLQueryTrackingGetError(resp, request)
return self._format_tracking(resp.body)
return self._format_tracking_properties(resp.body)

return self._execute(request, response_handler)

Expand Down Expand Up @@ -465,7 +456,7 @@ def set_tracking(self,
def response_handler(resp):
if not resp.is_success:
raise AQLQueryTrackingSetError(resp, request)
return self._format_tracking(resp.body)
return self._format_tracking_properties(resp.body)

return self._execute(request, response_handler)

Expand Down Expand Up @@ -563,6 +554,28 @@ class AQLQueryCache(APIWrapper):
def __repr__(self):
return '<AQLQueryCache in {}>'.format(self._conn.db_name)

# noinspection PyMethodMayBeStatic
def _format_cache_properties(self, body):
"""Format the query cache properties.
:param body: Response body.
:type body: dict
:return: Formatted body.
:rtype: dict
"""
body.pop('code', None)
body.pop('error', None)

if 'maxResults' in body:
body['max_results'] = body.pop('maxResults')
if 'maxResultsSize' in body:
body['max_results_size'] = body.pop('maxResultsSize')
if 'maxEntrySize' in body:
body['max_entry_size'] = body.pop('maxEntrySize')
if 'includeSystem' in body:
body['include_system'] = body.pop('includeSystem')
return body

def properties(self):
"""Return the query cache properties.
Expand All @@ -578,30 +591,47 @@ def properties(self):
def response_handler(resp):
if not resp.is_success:
raise AQLCachePropertiesError(resp, request)
return {
'mode': resp.body['mode'],
'limit': resp.body['maxResults']
}
return self._format_cache_properties(resp.body)

return self._execute(request, response_handler)

def configure(self, mode=None, limit=None):
def configure(self,
mode=None,
max_results=None,
max_results_size=None,
max_entry_size=None,
include_system=None):
"""Configure the query cache properties.
:param mode: Operation mode. Allowed values are "off", "on" and
"demand".
:type mode: str | unicode
:param limit: Max number of query results to be stored.
:type limit: int
:param max_results: Max number of query results stored per
database-specific cache.
:type max_results: int
:param max_results_size: Max cumulative size of query results stored
per database-specific cache.
:type max_results_size: int
:param max_entry_size: Max entry size of each query result stored per
database-specific cache.
:type max_entry_size: int
:param include_system: Store results of queries in system collections.
:type include_system: bool
:return: Query cache properties.
:rtype: dict
:raise arango.exceptions.AQLCacheConfigureError: If operation fails.
"""
data = {}
if mode is not None:
data['mode'] = mode
if limit is not None:
data['maxResults'] = limit
if max_results is not None:
data['maxResults'] = max_results
if max_results_size is not None:
data['maxResultsSize'] = max_results_size
if max_entry_size is not None:
data['maxEntrySize'] = max_entry_size
if include_system is not None:
data['includeSystem'] = include_system

request = Request(
method='put',
Expand All @@ -612,10 +642,7 @@ def configure(self, mode=None, limit=None):
def response_handler(resp):
if not resp.is_success:
raise AQLCacheConfigureError(resp, request)
return {
'mode': resp.body['mode'],
'limit': resp.body['maxResults']
}
return self._format_cache_properties(resp.body)

return self._execute(request, response_handler)

Expand All @@ -642,7 +669,7 @@ def clear(self):
"""Clear the query cache.
:return: True if query cache was cleared successfully.
:rtype: dict
:rtype: bool
:raise arango.exceptions.AQLCacheClearError: If operation fails.
"""
request = Request(
Expand Down

0 comments on commit 20118b9

Please sign in to comment.