Enable covered indexes for simple documents.

Refs #444
This commit is contained in:
Ross Lawley
2012-03-02 13:42:24 +00:00
parent bdf7187d5c
commit 32fc4152a7
3 changed files with 39 additions and 4 deletions

View File

@@ -273,16 +273,20 @@ class Q(QNode):
class QueryFieldList(object):
"""Object that handles combinations of .only() and .exclude() calls"""
ONLY = True
EXCLUDE = False
ONLY = 1
EXCLUDE = 0
def __init__(self, fields=[], value=ONLY, always_include=[]):
self.value = value
self.fields = set(fields)
self.always_include = set(always_include)
self._id = None
def as_dict(self):
return dict((field, self.value) for field in self.fields)
field_list = dict((field, self.value) for field in self.fields)
if self._id is not None:
field_list['_id'] = self._id
return field_list
def __add__(self, f):
if not self.fields:
@@ -298,6 +302,9 @@ class QueryFieldList(object):
self.value = self.ONLY
self.fields = f.fields - self.fields
if '_id' in f.fields:
self._id = f.value
if self.always_include:
if self.value is self.ONLY and self.fields:
self.fields = self.fields.union(self.always_include)