def query(cls, **kwds): """Interface to Cql from your model, which yields models""" #NOTE: Only static properties can be indexed by homer, # so we don't worry about querying for dynamic properties query = "" started = False for name in kwds: if not started: pattern = "%s=:%s" % (name, name) query += pattern started = True else: pattern = " AND %s=:%s" % (name, name) query += pattern q = 'SELECT * FROM %s WHERE %s' % (cls.kind(), query) query = CqlQuery(cls, q, **kwds) query.convert = True return query
def count(cls, **keywords): '''Counts all the instances of this Model from the datastore''' if not keywords: return CqlQuery(cls, "SELECT COUNT(*) FROM %s;" %(cls.kind(),)).fetchone() else: # Dynamically build the WHERE clause. extras = "" started = False for name in keywords: if not started: pattern = "%s=:%s" % (name, name) extras += pattern started = True else: pattern = " AND %s=:%s" % (name, name) query += pattern q = "SELECT COUNT(*) FROM %s WHERE %s;" % (cls.kind(), extras) query = CqlQuery(cls, q, **keywords) query.convert = True return query.fetchone()