Esempio n. 1
0
 def read(clasz, key, fetchmode=FetchMode.Property):
     '''Read a Model from Cassandra'''
     assert key and fetchmode, "specify key and fetchmode"
     assert key.complete(), "your key has to be complete"
     parent = ColumnParent(column_family = key.kind)
     predicate = None
     if fetchmode == FetchMode.Property:
         if key.columns:
             predicate = SlicePredicate(column_names = key.columns)
         else:
             type = Schema.ClassForModel(key.namespace, key.kind)
             names = fields(type, Property).keys() 
             columns = list(names)
             predicate = SlicePredicate(column_names = columns)
     elif fetchmode == FetchMode.All:
         range = SliceRange(start='', finish='', count = FETCHSIZE )
         predicate = SlicePredicate(slice_range=range)       
     found = None
     pool = poolFor(key.namespace)
     with using(pool) as conn:
         keyspace = keyspaceFor(key.namespace)
         conn.client.set_keyspace(keyspace)
         coscs = conn.client.get_slice(key.id, parent, predicate, clasz.consistency)
         found = MetaModel.load(key, coscs)
     return found    
Esempio n. 2
0
 def delete(clasz, *keys):
     '''Deletes a List of keys which represents Models'''
     for key in keys:
         assert key.complete(), "Your Key has to be complete to a delete"
         path = ColumnPath(column_family = key.kind)
         clock = time.time()
         pool = poolFor(key.namespace)
         with using(pool) as conn:
             logging.info("DELETING %s FROM CASSANDRA" % key )
             keyspace = keyspaceFor(key.namespace)
             conn.client.set_keyspace(keyspace)
             conn.client.remove(key.id, path, clock, clasz.consistency)