611
611
'AttributeValueList': [],
612
612
'ComparisonOperator': op,
615
615
# Special-case the ``NULL/NOT_NULL`` case.
616
616
if field_bits[-1] == 'null':
617
617
del lookup['AttributeValueList']
646
646
def query(self, limit=None, index=None, reverse=False, consistent=False,
647
attributes=None, **filter_kwargs):
649
649
Queries for a set of matching items in a DynamoDB table.
674
674
the data (more expensive). (Default: ``False`` - use eventually
675
675
consistent reads)
677
Optionally accepts a ``attributes`` parameter, which should be a
678
tuple. If you provide any attributes only these will be fetched
679
from DynamoDB. This uses the ``AttributesToGet`` and set's
680
``Select`` to ``SPECIFIC_ATTRIBUTES`` API.
677
682
Returns a ``ResultSet``, which transparently handles the pagination of
678
683
results you get back.
727
737
'reverse': reverse,
728
738
'consistent': consistent,
740
'attributes_to_get': attributes
730
742
results.to_call(self._query, **kwargs)
745
def query_count(self, index=None, consistent=False, **filter_kwargs):
747
Queries the exact count of matching items in a DynamoDB table.
749
Queries can be performed against a hash key, a hash+range key or
750
against any data stored in your local secondary indexes.
752
To specify the filters of the items you'd like to get, you can specify
753
the filters as kwargs. Each filter kwarg should follow the pattern
754
``<fieldname>__<filter_operation>=<value_to_look_for>``.
756
Optionally accepts an ``index`` parameter, which should be a string of
757
name of the local secondary index you want to query against.
760
Optionally accepts a ``consistent`` parameter, which should be a
761
boolean. If you provide ``True``, it will force a consistent read of
762
the data (more expensive). (Default: ``False`` - use eventually
765
Returns an integer which represents the exact amount of matched
770
# Look for last names equal to "Doe".
771
>>> users.query_count(last_name__eq='Doe')
774
# Use an LSI & a consistent read.
775
>>> users.query_count(
776
... date_joined__gte=1236451000,
778
... index='DateJoinedIndex',
784
key_conditions = self._build_filters(
786
using=QUERY_OPERATORS
789
raw_results = self.connection.query(
792
consistent_read=consistent,
794
key_conditions=key_conditions,
796
return int(raw_results.get('Count', 0))
733
798
def _query(self, limit=None, index=None, reverse=False, consistent=False,
734
exclusive_start_key=None, **filter_kwargs):
799
exclusive_start_key=None, select=None, attributes_to_get=None,
736
802
The internal method that performs the actual queries. Used extensively
737
803
by ``ResultSet`` to perform each (paginated) request.