Пример #1
0
 def delete(self, obj):
     assert type(obj) is self.model and obj.oid is not None
     if not ds.exists(obj.key):
         raise NotFoundError(obj.key)
     pl = ds.pipeline(True)
     self.__unindex_all(pl, obj)
     pl.delete(obj.key)
     pl.execute()
     obj.oid = None
Пример #2
0
 def update_all(self, hcont, obj):
     assert self.field.owned
     data = obj.make_dict()
     self.element_writer._check_unique_for_update(obj, data)
     pl = ds.pipeline(True)
     SortedSetWriter.raw_remove(self, pl, hcont, obj.oid)
     self.element_writer._do_update_attrs(pl, obj, data)
     score = getattr(obj, self.field.sort_field.name)
     SortedSetWriter.raw_append(self, pl, hcont, obj.oid, score)
     pl.execute()
Пример #3
0
 def append(self, hcont, value, score = None):
     assert hcont.target_type is self.target_type
     assert type(value) is self.target_type or (hasattr(value, 'model') and value.model is self.target_type)
     if self.target_has_id:
         value = value.oid
     assert value is not None
     if not self.index_key:
         self.raw_append(ds, hcont, value, score)
     elif self.unique_index:
         #TODO watch (optimistic lock) to allow multithread?
         if ds.hexists(self.index_key, value):
             raise UniqueError(self.index_key, value)
         else:
             pl = ds.pipeline(True)
             self.raw_append(pl, hcont, value, score)
             pl.hset(self.index_key, value, hcont.owner_id)
             pl.execute()
     else:
         pl = ds.pipeline(True)
         self.raw_append(pl, hcont, value, score)
         ikey = self.index_key + ':' + str(value)
         pl.sadd(ikey, hcont.owner_id)
         pl.execute()
Пример #4
0
 def remove(self, hcont, value):
     assert hcont.target_type is self.target_type
     assert type(value) is self.target_type or (hasattr(value, 'model') and value.model is self.target_type)
     if self.target_has_id:
         value = value.oid
     if not self.index_key:
         return self.raw_remove(ds, hcont, value)
     else:
         pl = ds.pipeline(True)
         if self.unique_index:
             pl.hdel(self.index_key, value)
         else:
             ikey = self.index_key + ':' + str(value)
             pl.srem(ikey, hcont.owner_id)
         self.raw_remove(pl, hcont, value)
         resp = pl.execute()
         return resp[1]
Пример #5
0
 def __update_attrs(self, obj, data):
     if len(data):
         self._check_unique_for_update(obj, data)
         pl = ds.pipeline(True)
         self._do_update_attrs(pl, obj, data)
         pl.execute()