11from __future__ import absolute_import , unicode_literals
22
3- from json import dumps
4-
53__all__ = ['AQL' , 'AQLQueryCache' ]
64
75from arango .api import APIWrapper
@@ -42,7 +40,7 @@ def __repr__(self):
4240 return '<AQL in {}>' .format (self ._conn .db_name )
4341
4442 # noinspection PyMethodMayBeStatic
45- def _format_tracking (self , body ):
43+ def _format_tracking_properties (self , body ):
4644 """Format the tracking properties.
4745
4846 :param body: Response body.
@@ -237,10 +235,10 @@ def execute(self,
237235 enterprise version of ArangoDB.
238236 :type satellite_sync_wait: int | float
239237 :param read_collections: Names of collections read during query
240- execution. Required for :doc:`transactions <transaction>` .
238+ execution. This parameter is deprecated .
241239 :type read_collections: [str | unicode]
242240 :param write_collections: Names of collections written to during query
243- execution. Required for :doc:`transactions <transaction>` .
241+ execution. This parameter is deprecated .
244242 :type write_collections: [str | unicode]
245243 :param stream: If set to True, query is executed in streaming fashion:
246244 query result is not stored server-side but calculated on the fly.
@@ -310,17 +308,10 @@ def execute(self,
310308 data ['options' ] = options
311309 data .update (options )
312310
313- command = 'db._query({}, {}, {}).toArray()' .format (
314- dumps (query ),
315- dumps (bind_vars ),
316- dumps (data ),
317- ) if self ._is_transaction else None
318-
319311 request = Request (
320312 method = 'post' ,
321313 endpoint = '/_api/cursor' ,
322314 data = data ,
323- command = command ,
324315 read = read_collections ,
325316 write = write_collections
326317 )
@@ -425,7 +416,7 @@ def tracking(self):
425416 def response_handler (resp ):
426417 if not resp .is_success :
427418 raise AQLQueryTrackingGetError (resp , request )
428- return self ._format_tracking (resp .body )
419+ return self ._format_tracking_properties (resp .body )
429420
430421 return self ._execute (request , response_handler )
431422
@@ -465,7 +456,7 @@ def set_tracking(self,
465456 def response_handler (resp ):
466457 if not resp .is_success :
467458 raise AQLQueryTrackingSetError (resp , request )
468- return self ._format_tracking (resp .body )
459+ return self ._format_tracking_properties (resp .body )
469460
470461 return self ._execute (request , response_handler )
471462
@@ -563,6 +554,28 @@ class AQLQueryCache(APIWrapper):
563554 def __repr__ (self ):
564555 return '<AQLQueryCache in {}>' .format (self ._conn .db_name )
565556
557+ # noinspection PyMethodMayBeStatic
558+ def _format_cache_properties (self , body ):
559+ """Format the query cache properties.
560+
561+ :param body: Response body.
562+ :type body: dict
563+ :return: Formatted body.
564+ :rtype: dict
565+ """
566+ body .pop ('code' , None )
567+ body .pop ('error' , None )
568+
569+ if 'maxResults' in body :
570+ body ['max_results' ] = body .pop ('maxResults' )
571+ if 'maxResultsSize' in body :
572+ body ['max_results_size' ] = body .pop ('maxResultsSize' )
573+ if 'maxEntrySize' in body :
574+ body ['max_entry_size' ] = body .pop ('maxEntrySize' )
575+ if 'includeSystem' in body :
576+ body ['include_system' ] = body .pop ('includeSystem' )
577+ return body
578+
566579 def properties (self ):
567580 """Return the query cache properties.
568581
@@ -578,30 +591,47 @@ def properties(self):
578591 def response_handler (resp ):
579592 if not resp .is_success :
580593 raise AQLCachePropertiesError (resp , request )
581- return {
582- 'mode' : resp .body ['mode' ],
583- 'limit' : resp .body ['maxResults' ]
584- }
594+ return self ._format_cache_properties (resp .body )
585595
586596 return self ._execute (request , response_handler )
587597
588- def configure (self , mode = None , limit = None ):
598+ def configure (self ,
599+ mode = None ,
600+ max_results = None ,
601+ max_results_size = None ,
602+ max_entry_size = None ,
603+ include_system = None ):
589604 """Configure the query cache properties.
590605
591606 :param mode: Operation mode. Allowed values are "off", "on" and
592607 "demand".
593608 :type mode: str | unicode
594- :param limit: Max number of query results to be stored.
595- :type limit: int
609+ :param max_results: Max number of query results stored per
610+ database-specific cache.
611+ :type max_results: int
612+ :param max_results_size: Max cumulative size of query results stored
613+ per database-specific cache.
614+ :type max_results_size: int
615+ :param max_entry_size: Max entry size of each query result stored per
616+ database-specific cache.
617+ :type max_entry_size: int
618+ :param include_system: Store results of queries in system collections.
619+ :type include_system: bool
596620 :return: Query cache properties.
597621 :rtype: dict
598622 :raise arango.exceptions.AQLCacheConfigureError: If operation fails.
599623 """
600624 data = {}
601625 if mode is not None :
602626 data ['mode' ] = mode
603- if limit is not None :
604- data ['maxResults' ] = limit
627+ if max_results is not None :
628+ data ['maxResults' ] = max_results
629+ if max_results_size is not None :
630+ data ['maxResultsSize' ] = max_results_size
631+ if max_entry_size is not None :
632+ data ['maxEntrySize' ] = max_entry_size
633+ if include_system is not None :
634+ data ['includeSystem' ] = include_system
605635
606636 request = Request (
607637 method = 'put' ,
@@ -612,10 +642,7 @@ def configure(self, mode=None, limit=None):
612642 def response_handler (resp ):
613643 if not resp .is_success :
614644 raise AQLCacheConfigureError (resp , request )
615- return {
616- 'mode' : resp .body ['mode' ],
617- 'limit' : resp .body ['maxResults' ]
618- }
645+ return self ._format_cache_properties (resp .body )
619646
620647 return self ._execute (request , response_handler )
621648
@@ -642,7 +669,7 @@ def clear(self):
642669 """Clear the query cache.
643670
644671 :return: True if query cache was cleared successfully.
645- :rtype: dict
672+ :rtype: bool
646673 :raise arango.exceptions.AQLCacheClearError: If operation fails.
647674 """
648675 request = Request (
0 commit comments