X-Git-Url: https://git.jsancho.org/?p=mojodb.git;a=blobdiff_plain;f=collection.py;fp=collection.py;h=7af5caaa7817e872bb856741945436f617162506;hp=664961a040680aebadf96e4e3724e1e765713b9c;hb=4a34db8a057d135225e70ede89b767e89f827c8f;hpb=2758cc7948327b7a0256a7ba3291024afea02552 diff --git a/collection.py b/collection.py index 664961a..7af5caa 100644 --- a/collection.py +++ b/collection.py @@ -36,13 +36,13 @@ class Collection(object): def _create_table(self): fields = [ - {'name': 'id', 'type': 'char', 'size': 32, 'primary': True}, + {'name': 'id', 'type': 'char', 'size': 512, 'primary': True}, ] return self.database.connection._create_table(self.database.db_name, '%s$_id' % self.table_name, fields) def _create_field(self, field_name): fields = [ - {'name': 'id', 'type': 'char', 'size': 32, 'primary': True}, + {'name': 'id', 'type': 'char', 'size': 512, 'primary': True}, {'name': 'value', 'type': 'text', 'null': False}, {'name': 'number', 'type': 'float'}, ] @@ -69,19 +69,20 @@ class Collection(object): else: docs = doc_or_docs for doc in docs: - if not '_id' in doc: - doc['_id'] = uuid.uuid4().hex + if not u'_id' in doc: + doc[u'_id'] = uuid.uuid4().hex self._insert_document(doc) if type(doc_or_docs) in (list, tuple): - return [d['_id'] for d in docs] + return [d[u'_id'] for d in docs] else: - return docs[0]['_id'] + return docs[0][u'_id'] def _insert_document(self, doc): table_id = '%s$_id' % self.table_name fields = self._get_fields() - self.database.connection._insert(self.database.db_name, table_id, {'id': doc['_id']}) + coded_id = cPickle.dumps(doc['_id']) + self.database.connection._insert(self.database.db_name, table_id, {'id': coded_id}) for f in doc: if f == '_id': continue @@ -89,7 +90,7 @@ class Collection(object): self._create_field(f) table_f = '%s$%s' % (self.table_name, f) values = { - 'id': doc['_id'], + 'id': coded_id, 'value': cPickle.dumps(doc[f]), } if type(doc[f]) in (int, float):