def COUNT(expression = None, distinct = False): if expression is None or isinstance(expression, Expression): return Expression('_COUNT', None, distinct = distinct) elif orm.isModel(expression): return Expression('_COUNT', None, table = expression) else: raise orm.QueryError('Argument must be a Field, an Expression or a Table.')
def getCreateTableQuery(cls, model): """Get CREATE TABLE statement for the given model in this DB. """ assert orm.isModel(model), 'Provide a Table subclass.' columns = cls._getCreateTableColumns(model) indexes = cls._getCreateTableIndexes(model) other = cls._getCreateTableOther(model) query = 'CREATE TABLE %s (' % str(model) query += '\n ' + ',\n '.join(columns) query += ',\n ' + ',\n '.join(indexes) query += '\n) ' + other + ';' # TODO return list of queries, instead of a single query return query
def _delete(self, table, where, limit = None): """DELETE FROM table_name [ WHERE expression ] [ LIMIT limit_amount ]""" assert orm.isModel(table) sql_w = ' WHERE ' + self.render(where) if where else '' return 'DELETE FROM %s%s;' % (table, sql_w)