From: Javier Sancho Date: Wed, 29 Jan 2014 15:32:03 +0000 (+0100) Subject: Search documents with numeric values X-Git-Url: https://git.jsancho.org/?p=mojodb.git;a=commitdiff_plain;h=2758cc7948327b7a0256a7ba3291024afea02552;ds=sidebyside Search documents with numeric values --- diff --git a/cursor.py b/cursor.py index 73a0c13..202c6c7 100644 --- a/cursor.py +++ b/cursor.py @@ -89,14 +89,18 @@ class Cursor(object): 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)) + if type(v) in (int, float): + field_q = self._get_cursor_field(table_id, table_f, field_name='number') + query['where'].append((field_q, '=', v)) + else: + field_q = self._get_cursor_field(table_id, table_f) + query['where'].append((field_q, '=', cPickle.dumps(v))) return self.collection.database.connection._get_cursor(self.collection.database.db_name, query) - def _get_cursor_field(self, table_id, table_field): + def _get_cursor_field(self, table_id, table_field, field_name='value'): return { - 'select': [(table_field, 'value')], + 'select': [(table_field, field_name)], 'from': [table_field], 'where': [((table_field, 'id'), '=', (table_id, 'id'))], }