]> git.jsancho.org Git - mojodb.git/blobdiff - cursor.py
Allow to save dictionaries, lists, tuples, etc, as document ids
[mojodb.git] / cursor.py
index 202c6c78aabb6429a8b8cd012b616e9f921a6169..ca9e2a4cc0f902dd8a3261b854ba35d64207b97e 100644 (file)
--- a/cursor.py
+++ b/cursor.py
@@ -89,7 +89,9 @@ 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):
+                if k == u'_id':
+                    query['where'].append(((table_id, 'id'), '=', cPickle.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))
                 else:
@@ -115,9 +117,9 @@ class Cursor(object):
                 raise StopIteration
             else:
                 document = {}
-                if '_id' in self.fields:
-                    document['_id'] = res[0]
-                fields_without_id = filter(lambda x: x != '_id', self.fields)
+                if u'_id' in self.fields:
+                    document[u'_id'] = cPickle.loads(res[0])
+                fields_without_id = filter(lambda x: x != u'_id', self.fields)
                 for i in xrange(len(fields_without_id)):
                     if not res[i + 1] is None:
                         document[fields_without_id[i]] = cPickle.loads(res[i + 1])