Added snapshot and timeout methods to QuerySet

This commit is contained in:
Harry Marr 2010-10-17 14:21:55 +01:00
parent 26723992e3
commit 012352cf24

View File

@ -401,6 +401,8 @@ class QuerySet(object):
self._where_clause = None self._where_clause = None
self._loaded_fields = [] self._loaded_fields = []
self._ordering = [] self._ordering = []
self._snapshot = False
self._timeout = True
# If inheritance is allowed, only return instances and instances of # If inheritance is allowed, only return instances and instances of
# subclasses of the class being used # subclasses of the class being used
@ -534,9 +536,12 @@ class QuerySet(object):
@property @property
def _cursor(self): def _cursor(self):
if self._cursor_obj is None: if self._cursor_obj is None:
cursor_args = {} cursor_args = {
'snapshot': self._snapshot,
'timeout': self._timeout,
}
if self._loaded_fields: if self._loaded_fields:
cursor_args = {'fields': self._loaded_fields} cursor_args['fields'] = self._loaded_fields
self._cursor_obj = self._collection.find(self._query, self._cursor_obj = self._collection.find(self._query,
**cursor_args) **cursor_args)
# Apply where clauses to cursor # Apply where clauses to cursor
@ -967,6 +972,20 @@ class QuerySet(object):
plan = pprint.pformat(plan) plan = pprint.pformat(plan)
return plan return plan
def snapshot(self, enabled):
"""Enable or disable snapshot mode when querying.
:param enabled: whether or not snapshot mode is enabled
"""
self._snapshot = enabled
def timeout(self, enabled):
"""Enable or disable the default mongod timeout when querying.
:param enabled: whether or not the timeout is used
"""
self._timeout = enabled
def delete(self, safe=False): def delete(self, safe=False):
"""Delete the documents matched by the query. """Delete the documents matched by the query.