def add_order_by(select_languoid: sa.sql.Select, *, order_by: str, column_for_path_order) -> sa.sql.Select: if order_by in (True, None, 'id'): return select_languoid.order_by(Languoid.id) elif order_by == 'path': return select_languoid.order_by(column_for_path_order) elif order_by is False: # pragma: no cover return select_languoid raise ValueError(f'order_by={order_by!r} not implemented') # pragma: no cover
def apply_to_statement(self, stmt: sa.sql.Select) -> sa.sql.Select: """ Modify the Select statement: add ORDER BY clause """ # Sort fields stmt = stmt.order_by(*self.compile_columns()) # Done return stmt
def order_date( q: sqla.sql.Select, desc: bool = True, ) -> sqla.sql.Select: item_published = orm_items.Item.Published if desc: item_published = sqla.desc(item_published) q = q.order_by(item_published) return q
def order_magic( q: sqla.sql.Select, user: orm_users.User, desc: bool = True, ) -> sqla.sql.Select: item_magic = orm_items.Item.magic.and_( orm_items.Magic.UserID == user.UserID, ) q = q.join(item_magic, isouter=True) magic_score = orm_items.Magic.Score if desc: magic_score = sqla.desc(magic_score) q = q.order_by(magic_score) return q
def order_title(q: sqla.sql.Select, ) -> sqla.sql.Select: q = q.order_by(sqla.collate(orm_feeds.Feed.Title, "NOCASE"), ) return q