def delete(cls, *keys): """Deletes this Model from the datastore and cache""" todelete = [] namespace, kind, member = Schema.Get(cls) for key in keys: assert isinstance(key, str) todelete.append(Key(namespace, kind, key)) Lisa.delete(*todelete)
def read(cls, key, mode = FetchMode.All): """Retreives objects from the datastore """ assert isinstance(key, (basestring, Key)) namespace, kind, member = Schema.Get(cls) if isinstance(key, Key): assert kind == key.kind, "Mismatched Model, reading a %s with %s" % (kind, key.kind) return Lisa.read(key, mode) else: key = Key(namespace, kind, key) return Lisa.read(key, mode)
def save(self): """Stores this object in the datastore and in the cache""" # Makes sure that all required properties are available before persistence. for name, prop in fields(self, Property).items(): if hasattr(prop, 'required') and prop.required: value = getattr(self, name) if prop.empty(value): raise BadValueError("Property: %s is required" % name) Lisa.save(self) self.differ.commit()
def deconvert(self, value): '''Pulls the referenced model from the datastore, and sets it''' key = eval(value) #Change the @value back to a key. if key: found = Lisa.read(key, FetchMode.All) return found else: return None
class BaseTestCase(TestCase): '''Base Class for all tests''' def setUp(self): '''Create the Lisa instance, we all know and love''' self.db = Lisa() self.connection = cql.connect("localhost", 9160).cursor() def tearDown(self): '''Release resources that have been allocated''' try: self.db.clear() Schema.Clear() self.connection.execute("DROP KEYSPACE %s" % Settings.keyspace()) self.connection.close() except Exception as e: print e
def setUp(self): '''Create the Lisa instance, we all know and love''' self.db = Lisa() self.connection = cql.connect("localhost", 9160).cursor()