class Cursor(object):
def __init__(self, collection, spec=None, fields=None, **kwargs):
+ if spec and not type(spec) is dict:
+ raise Exception("spec must be an instance of dict")
+
self.collection = collection
self.spec = spec
self.fields = self._get_fields(fields)
if first:
res_fields.add(f[0])
else:
- raise Exception(Errors['mix_fields_error'])
+ raise Exception("You cannot currently mix including and excluding fields. Contact us if this is an issue.")
elif not f[1]:
if not first:
res_fields.discard(f[0])
else:
- raise Exception(Errors['mix_fields_error'])
+ raise Exception("You cannot currently mix including and excluding fields. Contact us if this is an issue.")
if '_id' in fields and not fields['_id']:
res_fields.discard('_id')
else:
query['select'] = [(table_id, 'id')]
for f in filter(lambda x: x != '_id', self.fields):
table_f = '%s$%s' % (self.collection.table_name, f)
- q = {}
- q['select'] = [(table_f, 'value')]
- q['from'] = [table_f]
- q['where'] = [((table_f, 'id'), '=', (table_id, 'id'))]
+ q = self._get_cursor_field(table_id, table_f)
query['select'].append(q)
query['from'] = [table_id]
+ if self.spec:
+ query['where'] = []
+ for k, v in self.spec.iteritems():
+ table_f = '%s$%s' % (self.collection.table_name, k)
+ field_q = self._get_cursor_field(table_id, table_f)
+ query['where'].append((field_q, '=', v))
+
return self.collection.database.connection._get_cursor(self.collection.database.db_name, query)
+ def _get_cursor_field(self, table_id, table_field):
+ return {
+ 'select': [(table_field, 'value')],
+ 'from': [table_field],
+ 'where': [((table_field, 'id'), '=', (table_id, 'id'))],
+ }
+
def next(self):
if self.cursor:
res = self.collection.database.connection._next(self.cursor)
return document
else:
return None
-
-
-Errors = {
- 'mix_fields_error': 'You cannot currently mix including and excluding fields. Contact us if this is an issue.',
- }