1
1
from __future__ import absolute_import , unicode_literals
2
2
3
- from json import dumps
4
-
5
3
__all__ = ['AQL' , 'AQLQueryCache' ]
6
4
7
5
from arango .api import APIWrapper
@@ -42,7 +40,7 @@ def __repr__(self):
42
40
return '<AQL in {}>' .format (self ._conn .db_name )
43
41
44
42
# noinspection PyMethodMayBeStatic
45
- def _format_tracking (self , body ):
43
+ def _format_tracking_properties (self , body ):
46
44
"""Format the tracking properties.
47
45
48
46
:param body: Response body.
@@ -237,10 +235,10 @@ def execute(self,
237
235
enterprise version of ArangoDB.
238
236
:type satellite_sync_wait: int | float
239
237
:param read_collections: Names of collections read during query
240
- execution. Required for :doc:`transactions <transaction>` .
238
+ execution. This parameter is deprecated .
241
239
:type read_collections: [str | unicode]
242
240
:param write_collections: Names of collections written to during query
243
- execution. Required for :doc:`transactions <transaction>` .
241
+ execution. This parameter is deprecated .
244
242
:type write_collections: [str | unicode]
245
243
:param stream: If set to True, query is executed in streaming fashion:
246
244
query result is not stored server-side but calculated on the fly.
@@ -310,17 +308,10 @@ def execute(self,
310
308
data ['options' ] = options
311
309
data .update (options )
312
310
313
- command = 'db._query({}, {}, {}).toArray()' .format (
314
- dumps (query ),
315
- dumps (bind_vars ),
316
- dumps (data ),
317
- ) if self ._is_transaction else None
318
-
319
311
request = Request (
320
312
method = 'post' ,
321
313
endpoint = '/_api/cursor' ,
322
314
data = data ,
323
- command = command ,
324
315
read = read_collections ,
325
316
write = write_collections
326
317
)
@@ -425,7 +416,7 @@ def tracking(self):
425
416
def response_handler (resp ):
426
417
if not resp .is_success :
427
418
raise AQLQueryTrackingGetError (resp , request )
428
- return self ._format_tracking (resp .body )
419
+ return self ._format_tracking_properties (resp .body )
429
420
430
421
return self ._execute (request , response_handler )
431
422
@@ -465,7 +456,7 @@ def set_tracking(self,
465
456
def response_handler (resp ):
466
457
if not resp .is_success :
467
458
raise AQLQueryTrackingSetError (resp , request )
468
- return self ._format_tracking (resp .body )
459
+ return self ._format_tracking_properties (resp .body )
469
460
470
461
return self ._execute (request , response_handler )
471
462
@@ -563,6 +554,28 @@ class AQLQueryCache(APIWrapper):
563
554
def __repr__ (self ):
564
555
return '<AQLQueryCache in {}>' .format (self ._conn .db_name )
565
556
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
+
566
579
def properties (self ):
567
580
"""Return the query cache properties.
568
581
@@ -578,30 +591,47 @@ def properties(self):
578
591
def response_handler (resp ):
579
592
if not resp .is_success :
580
593
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 )
585
595
586
596
return self ._execute (request , response_handler )
587
597
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 ):
589
604
"""Configure the query cache properties.
590
605
591
606
:param mode: Operation mode. Allowed values are "off", "on" and
592
607
"demand".
593
608
: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
596
620
:return: Query cache properties.
597
621
:rtype: dict
598
622
:raise arango.exceptions.AQLCacheConfigureError: If operation fails.
599
623
"""
600
624
data = {}
601
625
if mode is not None :
602
626
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
605
635
606
636
request = Request (
607
637
method = 'put' ,
@@ -612,10 +642,7 @@ def configure(self, mode=None, limit=None):
612
642
def response_handler (resp ):
613
643
if not resp .is_success :
614
644
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 )
619
646
620
647
return self ._execute (request , response_handler )
621
648
@@ -642,7 +669,7 @@ def clear(self):
642
669
"""Clear the query cache.
643
670
644
671
:return: True if query cache was cleared successfully.
645
- :rtype: dict
672
+ :rtype: bool
646
673
:raise arango.exceptions.AQLCacheClearError: If operation fails.
647
674
"""
648
675
request = Request (
0 commit comments