def optimized_count(self, **kwargs): """Return count in optimized manner Apple.objects.filter(indice=4).count() Apple.objects.optimized_count(indice=4) """ if (len(kwargs) == 0): raise MissingKwargs("you must specify the filter clause") if (len(kwargs) > 1): raise TooManyKwargs() # do not care about more than one kwarg (key, value) = kwargs.items()[0] (nbe, column, qfilter) = tool.parse_kwarg(key) agg = 'agg_count' agf = agg.split('_') agt = util.AggTrigger(util.PG_BACKEND, self.model._meta.db_table, column) if nbe == 1: agf = agg elif nbe == 2: agf = agt.agg_function(agg, agf[1]) cursor = connection.cursor() qry = """SELECT {} FROM {} WHERE {} %s""" tbname = util.table_name(self.model._meta.db_table, column) cursor.execute(qry.format(agf, tbname, qfilter), [value]) row = cursor.fetchone() return row[0]
def delete_schema(): dynamodb = boto3.resource('dynamodb') util.delete_table_if_exists(dynamodb, util.table_name('sequences')) util.delete_table_if_exists(dynamodb, util.table_name('questions')) util.delete_table_if_exists(dynamodb, util.table_name('answers')) util.delete_table_if_exists(dynamodb, util.table_name('upvotes')) util.delete_table_if_exists(dynamodb, util.table_name('users')) util.delete_table_if_exists(dynamodb, util.table_name('tags')) util.delete_table_if_exists(dynamodb, util.table_name('question_tags'))
def table(cls, db): return db.Table(util.table_name('answers'))
def __init__(self, db, id): self._table = db.Table(util.table_name('questions')) self._id = id
def __init__(self, db, user_id): self._table = db.Table(util.table_name('users')) self._user_id = user_id
def __init__(self, db, name): self._table = db.Table(util.table_name('sequences')) self._name = name