X-Git-Url: https://git.jsancho.org/?p=mojodb.git;a=blobdiff_plain;f=cursor.py;fp=cursor.py;h=e07f237e792f0da9ab0005ab2a3bd327faea930a;hp=ef6328028141994ca9e775fb13f6a4be67f5604a;hb=2c1872fd5004c8464e146081b61783de47b87e2d;hpb=aed397c34f0bcc9eeb12e42256cc47e79e049971 diff --git a/cursor.py b/cursor.py index ef63280..e07f237 100644 --- a/cursor.py +++ b/cursor.py @@ -77,7 +77,7 @@ class Cursor(object): query = {} table_id = '%s$_id' % self.collection.table_name - query['select'] = [(table_id, 'id')] + query['select'] = [(table_id, 'value')] for f in filter(lambda x: x != '_id', self.fields): table_f = '%s$%s' % (self.collection.table_name, f) q = self._get_cursor_field(table_id, table_f) @@ -89,14 +89,17 @@ class Cursor(object): query['where'] = [] for k, v in self.spec.iteritems(): table_f = '%s$%s' % (self.collection.table_name, k) + if type(v) in (int, float): + field_name = 'number' + field_v = v + else: + field_name = 'value' + field_v = msgpack.dumps(v) if k == '_id': - query['where'].append(((table_id, 'id'), '=', msgpack.dumps(v))) - elif type(v) in (int, float): - field_q = self._get_cursor_field(table_id, table_f, field_name='number') - query['where'].append((field_q, '=', v)) + field_q = (table_id, field_name) else: - field_q = self._get_cursor_field(table_id, table_f) - query['where'].append((field_q, '=', msgpack.dumps(v))) + field_q = self._get_cursor_field(table_id, table_f, field_name=field_name) + query['where'].append((field_q, '=', field_v)) return self.collection.database.connection._get_cursor(self.collection.database.db_name, query)